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

RedisConnectionException after updating to version 2.1.0 from 2.0.0 #607

Closed
LarsSchlieper opened this issue Oct 10, 2022 · 12 comments
Closed
Assignees
Labels
question Have you tried our Slack workspace (https://testcontainers.slack.com)?

Comments

@LarsSchlieper
Copy link

LarsSchlieper commented Oct 10, 2022

Describe the bug
The connection to the container does not work with version 2.1.0, but it works with version 2.0.0.

To Reproduce

public SynchronizationProviderFixture()
    {
        Container = new TestcontainersBuilder<RedisTestcontainer>()
            .WithCleanUp(true)
            .WithImage("eqalpha/keydb:alpine")
            .WithExposedPort(DefaultRedisPort)
            .WithPortBinding(DefaultRedisPort, true)
            .Build();
        Container.ContainerPort = DefaultRedisPort;
    }
StackExchange.Redis.RedisConnectionException
It was not possible to connect to the redis server(s). 
UnableToConnect on localhost:49247/Interactive, Initializing/NotStarted, 
last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 2s ago, last-write: 2s ago, 
keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 9s ago, v: 2.2.4.27433

Desktop (please complete the following information):

  • Docker 20.10.17
  • DotNet 6.0.9
  • Windows 10

Additional context
It works for my colleagues, but not for me.

@HofmeisterAn
Copy link
Collaborator

Your setup works on my device too. Can you add the Docker logs to the issue? Can you add following builder configuration WithStartupCallback((_, ct) => Task.Delay(TimeSpan.FromSeconds(30), ct)) and test it again?

@HofmeisterAn HofmeisterAn added the question Have you tried our Slack workspace (https://testcontainers.slack.com)? label Oct 10, 2022
@LarsSchlieper
Copy link
Author

LarsSchlieper commented Oct 11, 2022

The additional configuration makes no difference.

Docker Logs

1:1:C 11 Oct 2022 08:16:17.376 # oO0OoO0OoO0Oo KeyDB is starting oO0OoO0OoO0Oo
1:1:C 11 Oct 2022 08:16:17.376 # KeyDB version=6.3.1, bits=64, commit=ee16abf0, modified=1, pid=1, just started
1:1:C 11 Oct 2022 08:16:17.376 # Configuration loaded
1:1:M 11 Oct 2022 08:16:17.377 * monotonic clock: POSIX clock_gettime
                                                                      
                  _                                                   
               _-(+)-_                                                
            _-- /   \ --_                                            
         _--   /     \   --_            KeyDB  6.3.1 (ee16abf0/1) 64 bit     
     __--     /       \     --__                                     
    (+) _    /         \    _ (+)       Running in standalone mode
     |   -- /           \ --   |        Port: 6379
     |     /--_   _   _--\     |        PID: 1
     |    /     -(+)-     \    |                                     
     |   /        |        \   |        https://docs.keydb.dev       
     |  /         |         \  |                                     
2022-10-11T08:16:17.725922539Z |          |          \ |                                     
    (+)_ -- -- -- | -- -- -- _(+)                                     
        --_       |       _--                                         
            --_   |   _--                                             
                -(+)-        KeyDB has now joined Snap! See the announcement at:  https://docs.keydb.dev/news

                                                                     
1:1:M 11 Oct 2022 08:16:17.725 # Server initialized
1:1:M 11 Oct 2022 08:16:17.725 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:18:M 11 Oct 2022 08:16:17.727 * Thread 0 alive.
1:21:M 11 Oct 2022 08:16:17.727 * Thread 1 alive.
Docker inspect output

[
    {
        "Id": "88d2a1f84e92b93a607ae87fd7d87202f17d1794d2e1677cecccee9719a5bc32",
        "Created": "2022-10-11T08:16:16.803412589Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "keydb-server",
            "/etc/keydb/keydb.conf"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 3142,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-10-11T08:16:17.366412251Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:47e269f553346e034afeaa49fa080d9710789afebad2b617de0ae4f11ff9f67a",
        "ResolvConfPath": "/var/lib/docker/containers/88d2a1f84e92b93a607ae87fd7d87202f17d1794d2e1677cecccee9719a5bc32/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/88d2a1f84e92b93a607ae87fd7d87202f17d1794d2e1677cecccee9719a5bc32/hostname",
        "HostsPath": "/var/lib/docker/containers/88d2a1f84e92b93a607ae87fd7d87202f17d1794d2e1677cecccee9719a5bc32/hosts",
        "LogPath": "/var/lib/docker/containers/88d2a1f84e92b93a607ae87fd7d87202f17d1794d2e1677cecccee9719a5bc32/88d2a1f84e92b93a607ae87fd7d87202f17d1794d2e1677cecccee9719a5bc32-json.log",
        "Name": "/stoic_bose",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "6379/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "0"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/885f4cec8ac9da3b3d784e380aada1b32505fc9bda83e7695defea58cb1561ae-init/diff:/var/lib/docker/overlay2/8ff29eb83b6732503df6322c7628c33c77d2b3ab3b2abfca419bd730319e46ff/diff:/var/lib/docker/overlay2/b78568c111c598c9869f3a7fbfe0a3a23556630bfe408613189d25202711e198/diff:/var/lib/docker/overlay2/801286f80b9f07cbc6deabad3a34e635f4fd267965811a49e77572318032ab4f/diff:/var/lib/docker/overlay2/d759bdcb5c0d77759fe1ed50c6ba2da1e0f02c73ef3985094716a0cb81ebb8a9/diff:/var/lib/docker/overlay2/998c37fca9a9eb271eac8e31e03b290c5fab0a9b4a2b0226f2e5cac6d8178928/diff:/var/lib/docker/overlay2/9fa9b0577639cdfbb2877f4422bfd4548a2ccf1b3959f0d31468a2757d593259/diff",
                "MergedDir": "/var/lib/docker/overlay2/885f4cec8ac9da3b3d784e380aada1b32505fc9bda83e7695defea58cb1561ae/merged",
                "UpperDir": "/var/lib/docker/overlay2/885f4cec8ac9da3b3d784e380aada1b32505fc9bda83e7695defea58cb1561ae/diff",
                "WorkDir": "/var/lib/docker/overlay2/885f4cec8ac9da3b3d784e380aada1b32505fc9bda83e7695defea58cb1561ae/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "d6530fb93caecb067add7b7ab853484e0ccb433f7e0c9c8097a5405dc41b6136",
                "Source": "/var/lib/docker/volumes/d6530fb93caecb067add7b7ab853484e0ccb433f7e0c9c8097a5405dc41b6136/_data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "88d2a1f84e92",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "6379/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "keydb-server",
                "/etc/keydb/keydb.conf"
            ],
            "Image": "eqalpha/keydb:alpine",
            "Volumes": {
                "/data": {}
            },
            "WorkingDir": "/data",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "testcontainers": "True",
                "testcontainers.resource-reaper-session": "1c86a8a2-c346-4dbf-923f-e20d2c95d102"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "09388ad65df3f57706ed207b66e42ac7d311093d0d2a178323c85246f6f6a278",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "6379/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "49159"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/09388ad65df3",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "b0dddb2c63faf56aed9d38b5749efa4b026f6ec33e0cd0f08e70556beb5201f1",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "3d4a3a8e0a0a01dfe597db32410547cd00736245014d8bd6e3cc92f4d7aed5bb",
                    "EndpointID": "b0dddb2c63faf56aed9d38b5749efa4b026f6ec33e0cd0f08e70556beb5201f1",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]

Additional context
HostPort is randomly generated in each run, but the correct one is used.

@HofmeisterAn
Copy link
Collaborator

The logs look good. Are you able to connect to {hostname}:{random_assigned_port}? What's /Interactive? Do you use the Hostname property to create your connection string?

@LarsSchlieper
Copy link
Author

LarsSchlieper commented Oct 11, 2022

I'm able to connect to {hostname}:{random_assigned_port} if the container is started via version 2.0.0 or manual.
By using version 2.1.0 neither i nor the program can connect to {hostname}:{random_assigned_port}.

/Interactive seems to be a standard of the library, i don't know.

We use the connection string directly from the container:

await Container.StartAsync();
_connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(Container.ConnectionString);

@HofmeisterAn HofmeisterAn self-assigned this Oct 11, 2022
@HofmeisterAn
Copy link
Collaborator

Have you tried one of the latest snapshot releases? Otherwise can you checkout which commit breaks your test? There are not too many commits between 2.0.0 and 2.1.0 (a kind of binary search should find it fast).

@LarsSchlieper
Copy link
Author

  • [2.0.0] fine
  • [2.0.1] DotNet.Testcontainers.Containers.ResourceReaperException: Initialization has been cancelled.
  • [2.1.0-beta.2536126951] fine
  • [2.1.0-beta.2543038937] DotNet.Testcontainers.Containers.ResourceReaperException: Initialization has been cancelled.
  • [2.1.0-beta.2561986470] StackExchange.Redis.RedisConnectionException
  • ...
  • [2.2.0-beta.2835065501] StackExchange.Redis.RedisConnectionException
`DotNet.Testcontainers.Containers.ResourceReaperException' of 2.0.1
Initialization has been cancelled.
{
  "ConnectionAttempts": 2,
  "LocalNetworkInterfaces": {
    XXX
  },
  "ExpectedHost": "localhost",
  "ExpectedPort": 49168,
  "ContainerInspection": {
    "ID": "91dee982973e55f6f5c9e35e05784cc548c1b43f6395fc01d9738425435100df",
    "Created": "2022-10-12T06:43:08.8487307Z",
    "Path": "/app",
    "Args": [],
    "State": {
      "Status": "running",
      "Running": true,
      "Paused": false,
      "Restarting": false,
      "OOMKilled": false,
      "Dead": false,
      "Pid": 5152,
      "ExitCode": 0,
      "Error": "",
      "StartedAt": "2022-10-12T06:43:09.409737322Z",
      "FinishedAt": "0001-01-01T00:00:00Z",
      "Health": null
    },
    "Image": "sha256:a0a36b674846145de03e245546b041e183f5a47e660fcba0d44f7c5392581f42",
    "ResolvConfPath": "/var/lib/docker/containers/91dee982973e55f6f5c9e35e05784cc548c1b43f6395fc01d9738425435100df/resolv.conf",
    "HostnamePath": "/var/lib/docker/containers/91dee982973e55f6f5c9e35e05784cc548c1b43f6395fc01d9738425435100df/hostname",
    "HostsPath": "/var/lib/docker/containers/91dee982973e55f6f5c9e35e05784cc548c1b43f6395fc01d9738425435100df/hosts",
    "LogPath": "/var/lib/docker/containers/91dee982973e55f6f5c9e35e05784cc548c1b43f6395fc01d9738425435100df/91dee982973e55f6f5c9e35e05784cc548c1b43f6395fc01d9738425435100df-json.log",
    "Node": null,
    "Name": "/testcontainers-ryuk-a1e3abf6-ad2b-47ad-9765-4325a0a2a6e0",
    "RestartCount": 0,
    "Driver": "overlay2",
    "Platform": "linux",
    "MountLabel": "",
    "ProcessLabel": "",
    "AppArmorProfile": "",
    "ExecIDs": null,
    "HostConfig": {
      "Binds": null,
      "ContainerIDFile": "",
      "LogConfig": {
        "Type": "json-file",
        "Config": {}
      },
      "NetworkMode": "default",
      "PortBindings": {
        "8080/tcp": [
          {
            "HostIP": "",
            "HostPort": "0"
          }
        ]
      },
      "RestartPolicy": {
        "Name": 0,
        "MaximumRetryCount": 0
      },
      "AutoRemove": true,
      "VolumeDriver": "",
      "VolumesFrom": null,
      "CapAdd": null,
      "CapDrop": null,
      "CgroupnsMode": "host",
      "DNS": null,
      "DNSOptions": null,
      "DNSSearch": null,
      "ExtraHosts": null,
      "GroupAdd": null,
      "IpcMode": "private",
      "Cgroup": "",
      "Links": null,
      "OomScoreAdj": 0,
      "PidMode": "",
      "Privileged": false,
      "PublishAllPorts": false,
      "ReadonlyRootfs": false,
      "SecurityOpt": null,
      "StorageOpt": null,
      "Tmpfs": null,
      "UTSMode": "",
      "UsernsMode": "",
      "ShmSize": 67108864,
      "Sysctls": null,
      "Runtime": "runc",
      "ConsoleSize": [
        0,
        0
      ],
      "Isolation": "",
      "CPUShares": 0,
      "Memory": 0,
      "NanoCPUs": 0,
      "CgroupParent": "",
      "BlkioWeight": 0,
      "BlkioWeightDevice": null,
      "BlkioDeviceReadBps": null,
      "BlkioDeviceWriteBps": null,
      "BlkioDeviceReadIOps": null,
      "BlkioDeviceWriteIOps": null,
      "CPUPeriod": 0,
      "CPUQuota": 0,
      "CPURealtimePeriod": 0,
      "CPURealtimeRuntime": 0,
      "CpusetCpus": "",
      "CpusetMems": "",
      "Devices": null,
      "DeviceCgroupRules": null,
      "DeviceRequests": null,
      "KernelMemory": 0,
      "KernelMemoryTCP": 0,
      "MemoryReservation": 0,
      "MemorySwap": 0,
      "MemorySwappiness": null,
      "OomKillDisable": false,
      "PidsLimit": null,
      "Ulimits": null,
      "CPUCount": 0,
      "CPUPercent": 0,
      "IOMaximumIOps": 0,
      "IOMaximumBandwidth": 0,
      "Mounts": [
        {
          "Type": "bind",
          "Source": "/var/run/docker.sock",
          "Target": "/var/run/docker.sock",
          "ReadOnly": true,
          "Consistency": null,
          "BindOptions": null,
          "VolumeOptions": null,
          "TmpfsOptions": null
        }
      ],
      "MaskedPaths": [
        "/proc/asound",
        "/proc/acpi",
        "/proc/kcore",
        "/proc/keys",
        "/proc/latency_stats",
        "/proc/timer_list",
        "/proc/timer_stats",
        "/proc/sched_debug",
        "/proc/scsi",
        "/sys/firmware"
      ],
      "ReadonlyPaths": [
        "/proc/bus",
        "/proc/fs",
        "/proc/irq",
        "/proc/sys",
        "/proc/sysrq-trigger"
      ],
      "Init": null
    },
    "GraphDriver": {
      "Data": {
        "LowerDir": "/var/lib/docker/overlay2/c1fcb4d82e640f5111e1126ca89c1ec80cfaecd72667077ea12b7163f6a0624d-init/diff:/var/lib/docker/overlay2/d40aa6642b11f6c243cd9d4df098bf2c9c3376ed46a141b1fc4305165e6199e4/diff:/var/lib/docker/overlay2/db81bd4d00d50cff7853238efb270220596dec1b46f205e495c24a32b33780c4/diff:/var/lib/docker/overlay2/be41b71f9b3891c4cbcd6f31ed534103dad3dce1673e410f301c1cc097d49138/diff",
        "MergedDir": "/var/lib/docker/overlay2/c1fcb4d82e640f5111e1126ca89c1ec80cfaecd72667077ea12b7163f6a0624d/merged",
        "UpperDir": "/var/lib/docker/overlay2/c1fcb4d82e640f5111e1126ca89c1ec80cfaecd72667077ea12b7163f6a0624d/diff",
        "WorkDir": "/var/lib/docker/overlay2/c1fcb4d82e640f5111e1126ca89c1ec80cfaecd72667077ea12b7163f6a0624d/work"
      },
      "Name": "overlay2"
    },
    "SizeRw": null,
    "SizeRootFs": null,
    "Mounts": [
      {
        "Type": "bind",
        "Name": null,
        "Source": "/var/run/docker.sock",
        "Destination": "/var/run/docker.sock",
        "Driver": null,
        "Mode": "",
        "RW": false,
        "Propagation": "rprivate"
      }
    ],
    "Config": {
      "Hostname": "91dee982973e",
      "Domainname": "",
      "User": "",
      "AttachStdin": false,
      "AttachStdout": false,
      "AttachStderr": false,
      "ExposedPorts": {
        "8080/tcp": {}
      },
      "Tty": false,
      "OpenStdin": false,
      "StdinOnce": false,
      "Env": [
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
      ],
      "Cmd": [
        "/app"
      ],
      "Healthcheck": null,
      "ArgsEscaped": false,
      "Image": "ghcr.io/psanetra/ryuk:2021.12.20",
      "Volumes": null,
      "WorkingDir": "",
      "Entrypoint": null,
      "NetworkDisabled": false,
      "MacAddress": null,
      "OnBuild": null,
      "Labels": {
        "testcontainers": "True",
        "testcontainers.resource-reaper-session": "00000000-0000-0000-0000-000000000000"
      },
      "StopSignal": null,
      "StopTimeout": null,
      "Shell": null
    },
    "NetworkSettings": {
      "Bridge": "",
      "SandboxID": "4310470d2973c1f73492b4ea8f08e4844b2c2ff78408b5096c9a257d6366a35f",
      "HairpinMode": false,
      "LinkLocalIPv6Address": "",
      "LinkLocalIPv6PrefixLen": 0,
      "Ports": {
        "8080/tcp": [
          {
            "HostIP": "0.0.0.0",
            "HostPort": "49168"
          }
        ]
      },
      "SandboxKey": "/var/run/docker/netns/4310470d2973",
      "SecondaryIPAddresses": null,
      "SecondaryIPv6Addresses": null,
      "EndpointID": "50e3ac3a8b4c430eb9d4873d5958cc64c04c4c2870a7f78dc38d5a1befe3bef4",
      "Gateway": "172.17.0.1",
      "GlobalIPv6Address": "",
      "GlobalIPv6PrefixLen": 0,
      "IPAddress": "172.17.0.2",
      "IPPrefixLen": 16,
      "IPv6Gateway": "",
      "MacAddress": "02:42:ac:11:00:02",
      "Networks": {
        "bridge": {
          "IPAMConfig": null,
          "Links": null,
          "Aliases": null,
          "NetworkID": "a21abfdd92f3ff854843e938ec1d25d8e176272c52710d1d43947a013f6cb2e2",
          "EndpointID": "50e3ac3a8b4c430eb9d4873d5958cc64c04c4c2870a7f78dc38d5a1befe3bef4",
          "Gateway": "172.17.0.1",
          "IPAddress": "172.17.0.2",
          "IPPrefixLen": 16,
          "IPv6Gateway": "",
          "GlobalIPv6Address": "",
          "GlobalIPv6PrefixLen": 0,
          "MacAddress": "02:42:ac:11:00:02",
          "DriverOpts": null
        }
      }
    }
  }
}
`DotNet.Testcontainers.Containers.ResourceReaperException' of 2.1.0-beta.2543038937
Initialization has been cancelled.
{
  "ConnectionAttempts": 2,
  "LocalNetworkInterfaces": {
    XXX
  },
  "ExpectedHost": "localhost",
  "ExpectedPort": 49160,
  "ContainerInspection": {
    "ID": "b5b146d2cfc45f02f171ad965862c05aeb060d84987f017b3cf7c4e98d281221",
    "Created": "2022-10-12T06:29:20.9557708Z",
    "Path": "/app",
    "Args": [],
    "State": {
      "Status": "running",
      "Running": true,
      "Paused": false,
      "Restarting": false,
      "OOMKilled": false,
      "Dead": false,
      "Pid": 3065,
      "ExitCode": 0,
      "Error": "",
      "StartedAt": "2022-10-12T06:29:21.531323091Z",
      "FinishedAt": "0001-01-01T00:00:00Z",
      "Health": null
    },
    "Image": "sha256:a0a36b674846145de03e245546b041e183f5a47e660fcba0d44f7c5392581f42",
    "ResolvConfPath": "/var/lib/docker/containers/b5b146d2cfc45f02f171ad965862c05aeb060d84987f017b3cf7c4e98d281221/resolv.conf",
    "HostnamePath": "/var/lib/docker/containers/b5b146d2cfc45f02f171ad965862c05aeb060d84987f017b3cf7c4e98d281221/hostname",
    "HostsPath": "/var/lib/docker/containers/b5b146d2cfc45f02f171ad965862c05aeb060d84987f017b3cf7c4e98d281221/hosts",
    "LogPath": "/var/lib/docker/containers/b5b146d2cfc45f02f171ad965862c05aeb060d84987f017b3cf7c4e98d281221/b5b146d2cfc45f02f171ad965862c05aeb060d84987f017b3cf7c4e98d281221-json.log",
    "Node": null,
    "Name": "/testcontainers-ryuk-10a3dc26-efa9-4c40-8231-42c5f6ac7f03",
    "RestartCount": 0,
    "Driver": "overlay2",
    "Platform": "linux",
    "MountLabel": "",
    "ProcessLabel": "",
    "AppArmorProfile": "",
    "ExecIDs": null,
    "HostConfig": {
      "Binds": null,
      "ContainerIDFile": "",
      "LogConfig": {
        "Type": "json-file",
        "Config": {}
      },
      "NetworkMode": "default",
      "PortBindings": {
        "8080/tcp": [
          {
            "HostIP": "",
            "HostPort": "0"
          }
        ]
      },
      "RestartPolicy": {
        "Name": 0,
        "MaximumRetryCount": 0
      },
      "AutoRemove": true,
      "VolumeDriver": "",
      "VolumesFrom": null,
      "CapAdd": null,
      "CapDrop": null,
      "CgroupnsMode": "host",
      "DNS": null,
      "DNSOptions": null,
      "DNSSearch": null,
      "ExtraHosts": null,
      "GroupAdd": null,
      "IpcMode": "private",
      "Cgroup": "",
      "Links": null,
      "OomScoreAdj": 0,
      "PidMode": "",
      "Privileged": false,
      "PublishAllPorts": false,
      "ReadonlyRootfs": false,
      "SecurityOpt": null,
      "StorageOpt": null,
      "Tmpfs": null,
      "UTSMode": "",
      "UsernsMode": "",
      "ShmSize": 67108864,
      "Sysctls": null,
      "Runtime": "runc",
      "ConsoleSize": [
        0,
        0
      ],
      "Isolation": "",
      "CPUShares": 0,
      "Memory": 0,
      "NanoCPUs": 0,
      "CgroupParent": "",
      "BlkioWeight": 0,
      "BlkioWeightDevice": null,
      "BlkioDeviceReadBps": null,
      "BlkioDeviceWriteBps": null,
      "BlkioDeviceReadIOps": null,
      "BlkioDeviceWriteIOps": null,
      "CPUPeriod": 0,
      "CPUQuota": 0,
      "CPURealtimePeriod": 0,
      "CPURealtimeRuntime": 0,
      "CpusetCpus": "",
      "CpusetMems": "",
      "Devices": null,
      "DeviceCgroupRules": null,
      "DeviceRequests": null,
      "KernelMemory": 0,
      "KernelMemoryTCP": 0,
      "MemoryReservation": 0,
      "MemorySwap": 0,
      "MemorySwappiness": null,
      "OomKillDisable": false,
      "PidsLimit": null,
      "Ulimits": null,
      "CPUCount": 0,
      "CPUPercent": 0,
      "IOMaximumIOps": 0,
      "IOMaximumBandwidth": 0,
      "Mounts": [
        {
          "Type": "bind",
          "Source": "/var/run/docker.sock",
          "Target": "/var/run/docker.sock",
          "ReadOnly": true,
          "Consistency": null,
          "BindOptions": null,
          "VolumeOptions": null,
          "TmpfsOptions": null
        }
      ],
      "MaskedPaths": [
        "/proc/asound",
        "/proc/acpi",
        "/proc/kcore",
        "/proc/keys",
        "/proc/latency_stats",
        "/proc/timer_list",
        "/proc/timer_stats",
        "/proc/sched_debug",
        "/proc/scsi",
        "/sys/firmware"
      ],
      "ReadonlyPaths": [
        "/proc/bus",
        "/proc/fs",
        "/proc/irq",
        "/proc/sys",
        "/proc/sysrq-trigger"
      ],
      "Init": null
    },
    "GraphDriver": {
      "Data": {
        "LowerDir": "/var/lib/docker/overlay2/9157053c7503b0e4e21c315344a049fbbdd282d38fefe13db5450cba029f8b77-init/diff:/var/lib/docker/overlay2/d40aa6642b11f6c243cd9d4df098bf2c9c3376ed46a141b1fc4305165e6199e4/diff:/var/lib/docker/overlay2/db81bd4d00d50cff7853238efb270220596dec1b46f205e495c24a32b33780c4/diff:/var/lib/docker/overlay2/be41b71f9b3891c4cbcd6f31ed534103dad3dce1673e410f301c1cc097d49138/diff",
        "MergedDir": "/var/lib/docker/overlay2/9157053c7503b0e4e21c315344a049fbbdd282d38fefe13db5450cba029f8b77/merged",
        "UpperDir": "/var/lib/docker/overlay2/9157053c7503b0e4e21c315344a049fbbdd282d38fefe13db5450cba029f8b77/diff",
        "WorkDir": "/var/lib/docker/overlay2/9157053c7503b0e4e21c315344a049fbbdd282d38fefe13db5450cba029f8b77/work"
      },
      "Name": "overlay2"
    },
    "SizeRw": null,
    "SizeRootFs": null,
    "Mounts": [
      {
        "Type": "bind",
        "Name": null,
        "Source": "/var/run/docker.sock",
        "Destination": "/var/run/docker.sock",
        "Driver": null,
        "Mode": "",
        "RW": false,
        "Propagation": "rprivate"
      }
    ],
    "Config": {
      "Hostname": "b5b146d2cfc4",
      "Domainname": "",
      "User": "",
      "AttachStdin": false,
      "AttachStdout": false,
      "AttachStderr": false,
      "ExposedPorts": {
        "8080/tcp": {}
      },
      "Tty": false,
      "OpenStdin": false,
      "StdinOnce": false,
      "Env": [
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
      ],
      "Cmd": [
        "/app"
      ],
      "Healthcheck": null,
      "ArgsEscaped": false,
      "Image": "ghcr.io/psanetra/ryuk:2021.12.20",
      "Volumes": null,
      "WorkingDir": "",
      "Entrypoint": null,
      "NetworkDisabled": false,
      "MacAddress": null,
      "OnBuild": null,
      "Labels": {
        "testcontainers": "True",
        "testcontainers.resource-reaper-session": "00000000-0000-0000-0000-000000000000"
      },
      "StopSignal": null,
      "StopTimeout": null,
      "Shell": null
    },
    "NetworkSettings": {
      "Bridge": "",
      "SandboxID": "2153cd89bceec313d72eac5295ff3e70229f9a59f61e2f4af4a7bd0767e2f36f",
      "HairpinMode": false,
      "LinkLocalIPv6Address": "",
      "LinkLocalIPv6PrefixLen": 0,
      "Ports": {
        "8080/tcp": [
          {
            "HostIP": "0.0.0.0",
            "HostPort": "49160"
          }
        ]
      },
      "SandboxKey": "/var/run/docker/netns/2153cd89bcee",
      "SecondaryIPAddresses": null,
      "SecondaryIPv6Addresses": null,
      "EndpointID": "1999e932f42fcc7f178d4783a47acdb2c279ca7b5a5bb8fd227913100c207b24",
      "Gateway": "172.17.0.1",
      "GlobalIPv6Address": "",
      "GlobalIPv6PrefixLen": 0,
      "IPAddress": "172.17.0.2",
      "IPPrefixLen": 16,
      "IPv6Gateway": "",
      "MacAddress": "02:42:ac:11:00:02",
      "Networks": {
        "bridge": {
          "IPAMConfig": null,
          "Links": null,
          "Aliases": null,
          "NetworkID": "a21abfdd92f3ff854843e938ec1d25d8e176272c52710d1d43947a013f6cb2e2",
          "EndpointID": "1999e932f42fcc7f178d4783a47acdb2c279ca7b5a5bb8fd227913100c207b24",
          "Gateway": "172.17.0.1",
          "IPAddress": "172.17.0.2",
          "IPPrefixLen": 16,
          "IPv6Gateway": "",
          "GlobalIPv6Address": "",
          "GlobalIPv6PrefixLen": 0,
          "MacAddress": "02:42:ac:11:00:02",
          "DriverOpts": null
        }
      }
    }
  }
}

@HofmeisterAn
Copy link
Collaborator

2.1.0-beta.2561986470124f0070f102d2687a018a2d07096398c5345ccb. These are the commits in the range of 2536126951 and 2561986470: https://github.com/testcontainers/testcontainers-dotnet/commits/develop?since=2022-06-21&until=2022-06-25.

If you run the container from CLI, how does your connection string look like?

@LarsSchlieper
Copy link
Author

LarsSchlieper commented Oct 12, 2022

DotNet.Testcontainers.Containers.ResourceReaperException occurs first with commit:

fix(#449): Do not set HostPort to null
ada9420

StackExchange.Redis.RedisConnectionException occurs first with the commit:

fix(#449): Don't let Docker Desktop for Windows choose the random public host port
124f007

Since I just read it in there: I use Docker Desktop

If i run the container from CLI i connect via localhost:{port}

@HofmeisterAn
Copy link
Collaborator

Since I just read it in there: I use Docker Desktop

Do you use Hyper-V? Maybe you run into:

What about this configuration?

public sealed class GitHub : IAsyncLifetime
{
  private const ushort RedisPort = 6379;

  private readonly ushort randomHostPort;

  private readonly ITestcontainersContainer container;

  public GitHub()
  {
    this.randomHostPort = GetPort();
    this.container = new TestcontainersBuilder<TestcontainersContainer>()
      .WithImage("eqalpha/keydb:alpine")
      .WithExposedPort(RedisPort)
      .WithPortBinding(this.randomHostPort, RedisPort)
      .Build();
  }

  public Task InitializeAsync()
  {
    return this.container.StartAsync();
  }

  public Task DisposeAsync()
  {
    return this.container.DisposeAsync().AsTask();
  }

  [Fact]
  public Task Issue607()
  {
    return ConnectionMultiplexer.ConnectAsync($"{this.container.Hostname}:{this.randomHostPort}");
  }

  private static ushort GetPort()
  {
    using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
    {
      socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
      return (ushort)((IPEndPoint)socket.LocalEndPoint).Port;
    }
  }
}

@LarsSchlieper
Copy link
Author

LarsSchlieper commented Oct 13, 2022

I use WSL 2.

I will have a look at the two issues.

Your Issue607-test is successful for 2.0.0, 2.1.0 and the latest 2.2.0-Beta but fails for 2.0.1 with DotNet.Testcontainers.Containers.ResourceReaperException on my device.

@HofmeisterAn
Copy link
Collaborator

This really sounds like the mention issues above. Is Hyper-V enabled / running? See e.g. #449 (comment).

@LarsSchlieper
Copy link
Author

LarsSchlieper commented Oct 13, 2022

This solved my Problem.
After enabling Hyper-V on Windows, it now works.

Thanks a lot.

It also solves for me the Issue docker/for-win#11584 you linked which was reproducible for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Have you tried our Slack workspace (https://testcontainers.slack.com)?
Projects
None yet
Development

No branches or pull requests

2 participants