testcontainers-dotnet: ResourceReaperException: Initialization has been cancelled
Describe the bug It looks like, that in some rare cases .NET Testcontainers can’t connect to Ryuk. I got a few times the following error:
DotNet.Testcontainers.Containers.ResourceReaperException : Initialization has been cancelled.
According the log messages, .NET Testcontainers tries to connect a couple of times. It looks like Ryuk is not ready to accept a connection. @PSanetra Do you have any idea? May this relate to the recent changes in the image?
To Reproduce -
Expected behavior .NET Testcontainers can connect to Ryuk.
Screenshots -
Desktop (please complete the following information):
- Docker Desktop 4.7.1 (77678)
Additional context Build 2193. May relate to: #423, #441, #443.
Workaround
Disable the ResourceReaper (TestcontainersSettings.ResourceReaperEnabled = false).
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 57 (14 by maintainers)
Commits related to this issue
- [#449] #IMPLEMENT 'assemblyName: DotNet.Testcontainers; function: ResourceReaper' {Add diagnostics information to ResourceReaperException.} — committed to PSanetra/dotnet-testcontainers by PSanetra 2 years ago
- [#449] #IMPLEMENT 'assemblyName: DotNet.Testcontainers; function: ResourceReaper' {Add diagnostic information to ResourceReaperException.} — committed to testcontainers/testcontainers-dotnet by PSanetra 2 years ago
- fix(#449): Do not set HostPort to null — committed to testcontainers/testcontainers-dotnet by HofmeisterAn 2 years ago
- fix(#449): Do not set HostPort to null — committed to testcontainers/testcontainers-dotnet by HofmeisterAn 2 years ago
- fix(#449): Don't let Docker Desktop for Windows choose the random public host port — committed to testcontainers/testcontainers-dotnet by HofmeisterAn 2 years ago
- fix(#449): Don't let Docker Desktop for Windows choose the random public host port — committed to testcontainers/testcontainers-dotnet by HofmeisterAn 2 years ago
It would be also interesting if something like this improves it:
Maybe the container field (value) is not up-to-date, and we return a value that’s obsolete in the meantime. You need to remove the timeout in your test then.
I prefer to find the root cause. The resource reaper must run reliable.
This time the log file looks good. The resource reaper gets the right port (
49156). I double-checked your sources (refactor-async-code) and noticed a few flaws. For instance:Doesn’t make sense. Even if you’re running on Windows, it’s still a Linux container. It should be
Wait.ForUnixContainer().UntilPortIsAvailable(MongoDbPort)instead. Take a look into the MongoDB example in this repository.Maybe you can figure out with
ResourceReaper.GetAndStartNewAsync()why Testcontainers can’t connect to the resource reaper on your machine.Configure the logger and set the level to debug. That should help to identify the issue.
It’s included in
2.0.1🤞.I wrote a quick “test” to make it easily reproductible
As you can see, it fails a lot!
error.txt This is what I was getting.
I can confirm it has not happened again after adding “WithWaitStrategy”
No, not lately. Looks stable for my builds, but this is an interesting comment: https://github.com/HofmeisterAn/dotnet-testcontainers/discussions/443#discussioncomment-2809925.