Skip to content
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]: Working with MsSql Container getting Initialization has been cancelled exception #794

Closed
iozcelik opened this issue Feb 19, 2023 · 19 comments
Assignees
Labels
bug Something isn't working

Comments

@iozcelik
Copy link

Testcontainers version

2.4.0

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host arch

x64

.NET version

7.0.3

Docker version

Client:
 Cloud integration: v1.0.29
 Version:           20.10.22
 API version:       1.41
 Go version:        go1.18.9
 Git commit:        3a2c30b
 Built:             Thu Dec 15 22:36:18 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.16.3 (96739)
 Engine:
  Version:          20.10.22
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       42c8b31
  Built:            Thu Dec 15 22:26:14 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.14
  GitCommit:        9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.0)
  compose: Docker Compose (Docker Inc., v2.15.1)
  dev: Docker Dev Environments (Docker Inc., v0.0.5)
  extension: Manages Docker extensions (Docker Inc., v0.2.17)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.23.0)

Server:
 Containers: 5
  Running: 0
  Paused: 0
  Stopped: 5
 Images: 17
 Server Version: 20.10.22
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.102.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.23GiB
 Name: docker-desktop
 ID: 4ISY:LGCG:5LYK:ITFR:XEMK:7OQS:4G7R:YW2W:VZJV:OECG:XLT3:GL6G
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

What happened?

I try to create a simple sample test. However I get an exception. DotNet.Testcontainers.Containers.ResourceReaperException : Initialization has been cancelled.

Docker logs not shown much information:

PS C:\Users\ismai> docker logs --follow testcontainers-ryuk-2780f9f8-55e4-4a1d-8d3a-efdc05c5a2ba
2023/02/19 19:37:20 Pinging Docker...
2023/02/19 19:37:20 Docker daemon is available!
2023/02/19 19:37:20 Starting on port 8080...
2023/02/19 19:37:20 Started!
panic: Timed out waiting for the first connection

goroutine 1 [running]:
main.main()
        /go/src/github.com/testcontainers/moby-ryuk/main.go:53 +0x4da

Relevant log output

No response

Additional information

My all test code is here.

using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Microsoft.Data.SqlClient;

namespace TestProject1;

public sealed class MsSqlTest : IAsyncLifetime {
    private static readonly ContainerBuilder<MsSqlTestcontainer> testcontainersBuilder = new ContainerBuilder<MsSqlTestcontainer>();
    private static readonly MsSqlTestcontainer customUserEntityDatabase = testcontainersBuilder.WithDatabase(new MsSqlTestcontainerConfiguration {
        Password = "localdevpassword#123",
        Database = "TestDatabase"
    }).WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(1433))
            .Build();

    public async Task DisposeAsync() {
        await customUserEntityDatabase.DisposeAsync();
    }

    public async Task InitializeAsync() {
        await customUserEntityDatabase.StartAsync();
    }

    [Fact]
    public async Task ShouldUseDefaultImageWhenImageIsNotSpecifiedAsync() {
        await InitContainerTestAsync();
    }

    private async Task InitContainerTestAsync() {
        using (var connection = new SqlConnection($"{customUserEntityDatabase.ConnectionString}TrustServerCertificate=true;")) {

            connection.Open();

            using (SqlCommand command = new SqlCommand("SELECT '1'", connection)) {
                using (SqlDataReader reader = command.ExecuteReader()) {
                    while (reader.Read()) {
                        Console.WriteLine("{0}", reader.GetString(0));
                    }
                }
            }
        }
    }
}
@iozcelik iozcelik added the bug Something isn't working label Feb 19, 2023
@iozcelik iozcelik changed the title [Bug]: [Bug]: Working with MsSql Container getting Initialization has been cancelled exception Feb 19, 2023
@HofmeisterAn
Copy link
Collaborator

Can you please take a look if you run into the excluded port ranges: docker/for-win#3171?

@iozcelik
Copy link
Author

I already check that issue. Also, I look java side. Actually I cannot pull testcontainers-ryuk manually.

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Feb 20, 2023

Actually I cannot pull testcontainers-ryuk manually.

docker pull testcontainers/ryuk does not work? Which error do you get? That sounds like a more general issue.

@iozcelik
Copy link
Author

Console output is:

C:\Windows\System32>docker pull testcontainers/ryuk
Using default tag: latest
latest: Pulling from testcontainers/ryuk
31603596830f: Pull complete
c307511530fc: Pull complete
6d9b4cc4a42f: Pull complete
Digest: sha256:b2762871bff62df9bfcec62609da821803a575e06d74aa7ce1654ded208cc7c5
Status: Downloaded newer image for testcontainers/ryuk:latest
docker.io/testcontainers/ryuk:latest

C:\Windows\System32>docker run testcontainers/ryuk
2023/02/20 10:27:41 Pinging Docker...
panic: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

goroutine 1 [running]:
main.main()
        /go/src/github.com/testcontainers/moby-ryuk/main.go:36 +0x457

I use Windows 11...

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Feb 20, 2023

You cannot run docker run testcontainers/ryuk, see usage. Testcontainers can start the Ryuk container, but cannot connect to it. Can you please share netsh interface ipv4 show excludedportrange protocol=tcp incl. the host port Docker assigns to the container.

@iozcelik
Copy link
Author

Command result:

C:\Windows\System32>netsh interface ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
        80          80
      8080        8080     *
      8884        8884
     50000       50059     *
     50080       50080
     50443       50443

* - Administered port exclusions.

image

After one minute, it is gone.

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Feb 20, 2023

This looks odd, the container has no port mapping 🤔. Can you add the container inspect (docker inspect ${container_id}) please? Can you try version 2.3.0? We added the following two lines to 2.4.0:

// Prepare Java alignment. Use an empty string instead of 0: https://github.com/docker/for-mac/issues/5588#issuecomment-934600089.
hostPort = "0".Equals(hostPort, StringComparison.OrdinalIgnoreCase) ? string.Empty : hostPort;

If you are using the develop branch, you can also comment out these two lines.

@iozcelik
Copy link
Author

image

With `2.3.0` it is working expected.

@HofmeisterAn
Copy link
Collaborator

Could you please test the develop branch without the two lines mentioned above? It would be really helpful in understanding whether this is a regression or not. I am unable to reproduce the issue. Thank you for your assistance.

@iozcelik
Copy link
Author

I test with develop branch and both cases are work well with comment and without comment that 2 lines. However with 2.4.0, I get same error.

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Feb 20, 2023

Interesting, I do not want to bother you, but can you test the following commit: eaa6068 😬? As I mentioned earlier, unfortunately, I am unable to reproduce it.

@HofmeisterAn
Copy link
Collaborator

We haven't received any response from you lately, and I wanted to check if you are still having issues with Ryuk?

@bealtis
Copy link

bealtis commented Feb 28, 2023

Hi, I had the same problem and got it working with version 2.3.0.
But I had to manually pull the required DB Images mcr.microsoft.com/mssql/server:2017-CU28-ubuntu-16.04 from Docker.

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Feb 28, 2023

Hi, I had the same problem and got it working with version 2.3.0.

Which version? 2.4.0? Which Docker version? Could you test develop instead?

But I had to manually pull the required DB Images mcr.microsoft.com/mssql/server:2017-CU28-ubuntu-16.04 from Docker.

This should not be necessary.

@iozcelik
Copy link
Author

We haven't received any response from you lately, and I wanted to check if you are still having issues with Ryuk?

Yes, still have problem. I use 2.4 version.

@HofmeisterAn
Copy link
Collaborator

Hm, based on the response it is very difficult for me to triage the issue 🤔.

@janwiebe-glasbergen
Copy link

I encountered the same issue.
It looks like it's a timing related issue, as the identical code worked on faster machines.

For me using the develop version solves the issue.

Could you release a patch version for 2.4.0?

@HofmeisterAn
Copy link
Collaborator

Could you release a patch version for 2.4.0?

We plan to publish a major release later next week.

@HofmeisterAn
Copy link
Collaborator

Since we now have the new release, I will close this issue. Let's see if it reappears 🤞.

@HofmeisterAn HofmeisterAn self-assigned this Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants