Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Container startup attempt backoff strategy #9479

Open
Two4 opened this issue Oct 30, 2024 · 2 comments
Open

[Feature]: Container startup attempt backoff strategy #9479

Two4 opened this issue Oct 30, 2024 · 2 comments

Comments

@Two4
Copy link

Two4 commented Oct 30, 2024

Module

None

Problem

I have a JUnit test extension that starts up a container. If multiple tests are executing in parallel in isolated JVMs, they contend for the container name and port bindings. One can work around this by giving it effectively infinite startup attempts and a reasonable startup timeout, but this generates excessive test logs from constant startup attempts.

Solution

Introduce a startup attempt backoff strategy option when constructing a container. Being able to exponentially backoff to a reasonable interval between startup attempts would help in reducing logs.

Benefit

This would benefit any situation where there is contention for exclusive resources between container instances, or any other situation where container startups are very flaky for an extended period, but eventual success is likely.

Alternatives

At the moment I'm using Awaitility to check for container name contention before attempting startup.

Would you like to help contributing this feature?

Yes

@Two4 Two4 changed the title [Feature]: [Feature]: Container startup attempt backoff strategy Oct 30, 2024
@eddumelendez
Copy link
Member

they contend for the container name and port bindings

Hi, can you elaborate about this please? Testcontainers promotes usage of random ports to be used and connect to the services running inside the container. At the same time, container names are not used by default. Of course, the API allows to do it but not in a easy way in order to avoid port collision.

@Two4
Copy link
Author

Two4 commented Nov 6, 2024

In this particular case, testcontainers is used to spin up a service on-demand for unit/integration testing. The port is unfortunately configured by the test, so there is no guarantee that the port will be free, and the test causing the contention may not even be in the same JVM. Rather than causing tests to fail (especially in CI/CD pipelines), I'd rather that testcontainers wait and retry for the contested container resources. The container name doesn't actually matter, but the point is moot, because the port bind does matter. However, I don't want to focus too much on my particular use case, because I think a container start retry backoff strategy would be applicable more widely, such as when external resources cannot be assured, or when dealing with contention with legacy systems that don't have any sort of lock-wait mechanism, or weird rate limiting in REST APIs, etc etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants