-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Bug]: Shutdown hook in RyukResourceReaper prevents a graceful shutdown with spring framework #8558
Comments
Will this be fixed any time soon? |
Also relevant for #7871 there was a solution proposed in the issue as well |
Hi @EAlf91, I cannot find the solution in the linked issue, could you please add a link to the specific comment? thanks! |
@jobayle It's mentioned here: #7871 (comment) but it would require a change I guess. The author made the hook configurable via spring properties: alex-arana@a0fcbdf I didn't try it myself and didn't see any way to configure this without using this fork. I'd highly appreciate to see a revert of #7717 or maybe using this way to configure it via spring properties |
Thanks @EAlf91, but imho, this is not a viable solution if we have to maintain a patched version of testcontainers. |
Any progress on this issue? |
@eddumelendez @bsideup @kiview Mention you all because you were working on PR which lead to this issue: #7717 Could you please take a brief look on this 🙏 |
Hey @jobayle,
This is of course a situation we would like to solve. What absolute amount of time are we talking abut here? I am not sure #8732 is the right approach though, since this would still require all affected users, to apply this config option (not ideal). We could make configuration more programmatically accessible, but this would also require downstream integration changes by the Spring project. Since a considerable amount of Testcontainers users are also Spring users, I think reverting the change and accept the containers lingering for some time after process termination can be the better DX, WDYT @eddumelendez? |
Hi @kiview, sure:
So roughly a whole minute! By enabling container reuse to simulate how things worked before #7717, the shutdown is almost instant:
Yes, I'd really love a fix or a revert, thanks 🙂 |
Thanks for sharing @jobayle, 1 minute is really not acceptable, will sync with @eddumelendez on how to best proceed with this and resolve the situation 👍. |
The registering of shutdown hook also has other problems, such as classloader issues in some specific use-cases. Considering this, I vote for reverting the change that introduced the shutdown hook. Or at least made it configurable (and 'off' by default). The solution of this problem will also solve the problem of using Testcontainers from Maven (e.g. #7923, #1454, testcontainers/testcontainers-jooq-codegen-maven-plugin#37) if shutdown hook will not be registered by default or at least configurable. |
Hi, I have created a branch revert-shutdown-hook, which is available via jitpack. I'm also using it in one of the projects available here. However, in the case of artemis the behavior is the same with or without this change. I would like to add a friendly reminder about sharing a project that reproduces the issue to help maintainers. You can also use this commit in your projects in order to help with the reproducer. I have few more examples https://github.com/eddumelendez/testcontainers-r2dbc We have agreed to revert the change if there is a real impact but we have not seen any so far. Again, a reproducer would help. |
Hi, I've spent a few hours investigating the issue and making a reproducer: https://github.com/jobayle/repro-tc-shutdownhook See the shutdown time when the integration tests are run in a github action : first line:
last line:
More than one minute. |
Thanks, @jobayle! really appreciate sharing a reproducer and the context. |
Just sharing some updates. Thanks to the reproducer I can see how the gradle project takes 2m 40s on my machine and the shutdown takes a lot of time. For testing purposes I did the same migrating the project to maven and it ran under 1m 20s. I didn't catch it due to the projects I shared before were only maven projects. It's interesting! This is just an update and not a statement about not fixing it or saying move to maven. I'll be deep dive a little bit more but probably the easiest and quick solution would be reverting the change as it has been suggested. Thanks again for the reproducer, it helps to move things faster! |
Are you saying that running the same tests using Maven instead of Gradle reduces the tests running time from 2m 40s to 1m 20s or just the whole build time is reduced from 2m 40s to 1m 20s (for reasons unrelated to running integration tests, e.g. downloading artifacts)? P.S. It's interesting that I cannot reproduce slow running tests with this project. They are usually finising in 23s. Of course, I see many unexpected errors in the logs due to premature containers shutdown, such as:
But long-running tests I cannot reproduce. Maybe the default timeout is different depending on the OS (I tried with Windows) or something.. Though, in other (real) projects I can still reproduce slow tests. The root cause (premature containers shutdown) is still easily reproducible. It is just the effect from it that is different depending on specific technologies and configuration (such as timeout) used. For example, in one of the projects I "fixed" the long-running tests problem by modifying the timeout of connection pool:
(the default is 30000). |
@xak2000 well, I'm working on windows and the github action runs on Ubuntu, so it's probably not OS dependent. Maybe it depends on the version of the JVM? or the vendor (Oracle, or Eclipse, or redhat...) Maybe there's a difference in shutdown hook processing somewhere 🤔 Or maybe it's because of hardware, if your machine is so powerful it manages to run most of the shutdown hooks before ruyk terminates the containers? |
@jobayle I'm not sure what is the reason. The containers are definitely terminated when shutdown listener is executed because I see errors like this in the logs: Logs
I think it could be ordering and speed of shutdown of different systems issue, yes. As we see, it is Update: @EventListener
fun handleShutdown(ctxStatus: ContextClosedEvent) {
Thread.sleep(1000)
logger.info("UPDATING MACHINE CONFIGURATION STATUS=SHUTDOWN")
machineRepository.updateRunningStatus(machineConfiguration.name, RunningStatus.OFFLINE)
} This way the tests are executed in a solid 1m 57s. Yay! 🎉😂 With many
and
|
Another update: I ran My focus has been on test execution time, dependencies were already downloaded. |
Module
Core
Testcontainers version
1.19.7
Using the latest Testcontainers version?
Yes
Host OS
Linux, Windows
Host Arch
x86_64
Docker version
Client: Cloud integration: v1.0.35+desktop.13 Version: 26.0.0 API version: 1.45 Go version: go1.21.8 Git commit: 2ae903e Built: Wed Mar 20 15:18:56 2024 OS/Arch: windows/amd64 Context: default Server: Docker Desktop 4.29.0 (145265) Engine: Version: 26.0.0 API version: 1.45 (minimum version 1.24) Go version: go1.21.8 Git commit: 8b79278 Built: Wed Mar 20 15:18:01 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0
What happened?
Dears,
With the introduction of this feature: #7717
The ryuk instance is terminated by a shutdown hook, therefore all containers are closed very early.
This prevents other shutdown hooks (eg: those set by the spring framework) to perform actions needed for a graceful shutdown that still require containers to be up.
Due to a retry mechanism in Spring's shutdown hook, it greatly increases the overall time to run tests!
Could you please revert this change or introduce a mean to disable this shutdown hook, thanks!
Relevant log output
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: