ResourceReaperException: Initialization has been cancelled

See original GitHub issue

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).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:57 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
HofmeisterAncommented, Jun 15, 2022

It would be also interesting if something like this improves it:

diff --git a/src/DotNet.Testcontainers/Containers/ResourceReaper.cs b/src/DotNet.Testcontainers/Containers/ResourceReaper.cs
index a36bf88..31e3181 100644
--- a/src/DotNet.Testcontainers/Containers/ResourceReaper.cs
+++ b/src/DotNet.Testcontainers/Containers/ResourceReaper.cs
@@ -48,6 +48,7 @@ namespace DotNet.Testcontainers.Containers
         .WithExposedPort(RyukPort)
         .WithPortBinding(RyukPort, true)
         .WithBindMount("/var/run/docker.sock", "/var/run/docker.sock", AccessMode.ReadOnly)
+        .WithStartupCallback((resourceReaper, ct) => Task.Delay(TimeSpan.FromSeconds(5), ct))
         .Build();
 
       this.SessionId = sessionId;

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.

Your proposition here is a good idea #443 (reply in thread)

I prefer to find the root cause. The resource reaper must run reliable.

1reaction
HofmeisterAncommented, Jun 22, 2022

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:

var waitOS = EnvironmentTools.IsWindows()
    ? Wait.ForWindowsContainer()
    : Wait.ForUnixContainer();

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application works with docker command but not ...
the problem is that the tests run correctly using the command ... ResourceReaperException : Initialization has been cancelled.
Read more >
Waiting for containers to start or be ready
Checks that the container is running and has been running for a defined minimum period of time.
Read more >
Resource Reaper
Testcontainers automatically assigns a Resource Reaper session id to each Docker resource. After the tests are finished — whether they are successful or...
Read more >
Initialization Strategies With Testcontainers For Integration ...
Learn about several initialization strategies for Testcontainers when writing integration tests: executing commands, mounting files, etc.
Read more >
how to properly configure Testcontainers to run PostgreSql ...
I am trying to use Testcontainers dotnet to run postgreSql container for integration testing. I found this code online but I am getting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found