-
-
Notifications
You must be signed in to change notification settings - Fork 503
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]: intermittent "port not found" error preventing Kafka and generic containers from starting #2670
Comments
Same issue, solved with: // HOTFIX: testcontainers-go v0.32.0
// https://github.com/testcontainers/testcontainers-go/issues/2670
type hotfix2670 struct{}
func (h hotfix2670) Customize(req *testcontainers.GenericContainerRequest) error {
originalHook := req.LifecycleHooks[0].PostStarts[0]
req.LifecycleHooks[0].PostStarts[0] = func(ctx context.Context, container testcontainers.Container) error {
var err error
for retry := 0; retry < 10; retry++ {
err = originalHook(ctx, container)
if err == nil {
break
}
time.Sleep(time.Second)
}
return err
}
return nil
}
func setupKafka(t *testing.T, ctx context.Context) *kafka.KafkaContainer {
t.Helper()
testcontainers.Logger = log.New(io.Discard, "", 0)
kafkaContainer, err := kafka.Run(ctx, "confluentinc/confluent-local:7.5.0",
kafka.WithClusterID("test-cluster"),
hotfix2670{},
)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, kafkaContainer.Terminate(ctx)) })
return kafkaContainer
} |
@ar-sematell yeah, my solution was very similar. Unfortunately, it only tackles the LifecycleHooks part. The second problem with |
Can you check if #2696 fixes this? |
@stevenh I tested with pseudo module version of I tried with few batches of 10 and with v0.32.0, about 50% of container starts failed. With the new patch, I don't see any failures. |
@aakso we released If fixed, I think we can close this one, thanks! |
Unforunately I get: |
Looks like this will need to reaper rework, do you have a simple test case? |
Unfortunately the test case is relatively complicated, it will take a bit of effort to boil it down to a simpler examplar |
Testcontainers version
0.32.0
Using the latest Testcontainers version?
Yes
Host OS
MacOS
Host arch
ARM
Go version
1.21.12
Docker version
Client: Version: 27.1.1 API version: 1.46 Go version: go1.21.12 Git commit: 6312585 Built: Tue Jul 23 19:54:12 2024 OS/Arch: darwin/arm64 Context: desktop-linux Server: Docker Desktop 4.33.0 (160616) Engine: Version: 27.1.1 API version: 1.46 (minimum version 1.24) Go version: go1.21.12 Git commit: cc13f95 Built: Tue Jul 23 19:57:14 2024 OS/Arch: linux/arm64 Experimental: true containerd: Version: 1.7.19 GitCommit: 2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41 runc: Version: 1.7.19 GitCommit: v1.1.13-0-g58aa920 docker-init: Version: 0.19.0 GitCommit: de40ad0
Docker info
What happened?
related to #2543
Unfortunately, the "port not found" error still seems to be present with v0.32.0.
I see it mainly with the Kafka module but also occasionally with
testcontainers.GenericContainer
too.The code snippet I'm using the start the Kafka test container:
So pretty standard.
Relevant log output
Additional information
I'm able to mitigate the error for Kafka module by wrapping the
PostStarts
lifecycle hooks and retrying on error. In my case it's the first hook that always fails. It seems to fail toc.MappedPort
call. So far, a single retry has been enough to mitigate the problem.The text was updated successfully, but these errors were encountered: