-
-
Notifications
You must be signed in to change notification settings - Fork 512
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]: Fail to start Kafka container (KRaft) with basic setup #2543
Comments
I am also experiencing this issue and have been able to reproduce it. It appears to be related to the PostStartLifecycleHook. The Kafka module uses the PostStart LifecycleHook to get the mapped port, which is used to create the Kafka startup script. However, when PostStart is called, the Docker container has not yet resolved the port mapping, causing the port not found error. While I am not certain if there is a straightforward solution, I have found a less elegant solution to resolve this issue. Simply adding a sleep at the beginning of the Kafka PostStart hook works fine in my tests, and we can make it configurable as needed. I will suggest a PR for review. @mdelapenya, do you know of a way to wait until Docker resolves the port mapping before the PostStart hook? |
This reverts commit 225f6dc. It was done just to undertand the cause and now we can revert it.
This reverts commit 225f6dc. It was done just to undertand the cause and now we can revert it.
@wilsouza , with adding a delay, did the problem go away completely for you? My colleague @grevend is also running into this issue, on a Mac (for Linux I cannot reproduce it). And we both tried adding delays, but also retries, and neither worked consistently. So we are now wondering if its really the same issue, or slightly different. Note we're still debugging further, seeing if we can find something to make it work more consistently, but so far it either works, or not (delays etc having no positive effect). |
I experience the same behaviour with the Redpanda module. Also tried older versions of testcontainers with the same result. Recently updated to the latest Docker Desktop. |
Thank you for sharing the details of the problems you're encountering.
Yes, adding a delay has completely resolved the issue for me. I'm running an internal version with this solution and haven't experienced any problems. I’ve also tested it on my Mac with an M1 processor without issues.
Have you tried running version #2552 with a custom wait time? Could you try running it with a custom timeout to see if it resolves the issue on your end? |
@wilsouza we tried with waits, unfortunately though, the wait needs to be pretty long to be stable (3-5 seconds). What makes that unacceptable from my perspective, is that the wait isn't needed on Linux based systems. Even if for a second, it would add a second to every test run, for every time the Kafka container needs to be started. We also further looked into why some retry mechanism doesn't work and found the cause. Line 182 in d4a21ea
Line 169 in d4a21ea
Which is then the reason why a retry doesn't work (if it once gets a wrong response, it always gets the wrong response), and a initial delay somehow works as it gives Docker a chance to set up the port mapping. I'm happy to provide assistance to any solution, but would really like to hear @mdelapenya 's perspective. Because I'm wondering if caching that And of course the question remains why the port mapping has some delay in the first place for MacOS, but maybe that's due to the nature of how Docker works there. |
Maybe it relates to the fact MacOS uses a Virtual Machine to host docker containers 🤔 Maybe the port is mapped in the VM, but not in the MacOS host machine. |
For the record, I have this behaviour also on a linux machine running ubuntu:
|
This reverts commit 225f6dc. It was done just to undertand the cause and now we can revert it.
any update on this? |
Got hit with this bug today on my Mac. Happens randomly. I'm using the latest testcontainers version. |
I think that this issue can be closed now that it has been addressed in @mdelapenya PR, #2606. What do you think @mdelapenya? |
This issue seem to be resolved for me when upgraded to v0.32.0. I will close this now, thanks to everyone that was involved, this is much appreciated! |
thanks folks for your support! I'm currently at Gophercon, and I will go back to regular work next Monday 🙏 |
Testcontainers version
0.31.0
Using the latest Testcontainers version?
Yes
Host OS
Mac
Host arch
ARM
Go version
1.22.3
Docker version
Client: Docker Engine - Community Version: 24.0.6 API version: 1.43 Go version: go1.21.0 Git commit: ed223bc820 Built: Thu Aug 31 17:24:32 2023 OS/Arch: darwin/arm64 Context: desktop-linux Server: Docker Desktop 4.30.0 (149282) Engine: Version: 26.1.1 API version: 1.45 (minimum version 1.24) Go version: go1.21.9 Git commit: ac2de55 Built: Tue Apr 30 11:48:04 2024 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.6.31 GitCommit: e377cd56a71523140ca6ae87e30244719194a521 runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0
Docker info
What happened?
I followed the documentation on how to use kafka testcontainers and at first it worked randomly (got the container running), and now it does not work constantly ending up with the "port not found" error after waiting the 1m timeout.
Relevant log output
Additional information
This is the complete program I am running to reproduce (started an empty project):
Here is the mod file
The text was updated successfully, but these errors were encountered: