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

Running image timeout problem #682

Closed
szagi3891 opened this issue Nov 30, 2023 · 6 comments
Closed

Running image timeout problem #682

szagi3891 opened this issue Nov 30, 2023 · 6 comments

Comments

@szagi3891
Copy link

Expected Behaviour
I expected the code to execute correctly:

import { GenericContainer, Wait } from 'testcontainers';

const main = async (): Promise<void> => {

    const container = await new GenericContainer('surrealdb/surrealdb:1.0.0')
        .withCommand(['start', '--strict', '--auth', '--log', 'debug', '-u', 'root', '-p', 'root', '--allow-guests'])
        .withExposedPorts(8000)
        .start();

    const host = container.getHost();
    const port = container.getMappedPort(8000);

    console.info(`host=${host} port=${port}`);

    //space for my tests

    await container.stop();
};

main().then(() => {
    console.info('end');
}).catch((error) => {
    console.error(error);
});

Actual Behaviour
The program ends with an error

Testcontainer Logs
(I don't know what to type here)

Steps to Reproduce

  1. git clone https://github.com/szagi3891/testcontainer-bug
  2. npm install
  3. npx run index.ts
  4. See error...
grzegorz@MacBook-Pro-playbook testcontainers-bug % npx tsx index.ts
(node:17861) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
oError: Port 8000 not bound after 60000ms
    at <anonymous> (/Users/grzegorz/Desktop/notatki/testcontainers-bug/node_modules/testcontainers/src/wait-strategies/host-port-wait-strategy.ts:52:15)
    at IntervalRetry.retryUntil (/Users/grzegorz/Desktop/notatki/testcontainers-bug/node_modules/testcontainers/src/common/retry.ts:49:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at HostPortWaitStrategy.waitForPort (/Users/grzegorz/Desktop/notatki/testcontainers-bug/node_modules/testcontainers/src/wait-strategies/host-port-wait-strategy.ts:46:5)
    at HostPortWaitStrategy.waitForInternalPorts (/Users/grzegorz/Desktop/notatki/testcontainers-bug/node_modules/testcontainers/src/wait-strategies/host-port-wait-strategy.ts:40:7)
    at async Promise.all (index 1)
    at HostPortWaitStrategy.waitUntilReady (/Users/grzegorz/Desktop/notatki/testcontainers-bug/node_modules/testcontainers/src/wait-strategies/host-port-wait-strategy.ts:14:5)
    at waitForContainer (/Users/grzegorz/Desktop/notatki/testcontainers-bug/node_modules/testcontainers/src/wait-strategies/wait-for-container.ts:17:5)
    at GenericContainer.startContainer (/Users/grzegorz/Desktop/notatki/testcontainers-bug/node_modules/testcontainers/src/generic-container/generic-container.ts:201:5)
    at main (/Users/grzegorz/Desktop/notatki/testcontainers-bug/index.ts:5:23)
grzegorz@MacBook-Pro-playbook testcontainers-bug %  

Environment Information

  • Operating System: MacOs Ventura 13.6
  • Docker Version: Docker version 23.0.5, build bc4487a
  • Node version: v21.2.0
  • Testcontainers version: 10.3.2
@cristianrgreco
Copy link
Collaborator

Testcontainer Logs
(I don't know what to type here)

https://node.testcontainers.org/configuration/#logs


I assume you are not seeing an error when running any examples from the docs, so why do you think this is an issue with Testcontainers and not with the way you are starting your container?

@szagi3891
Copy link
Author

I don't assume anything. I am learning the tool. I made a ticket because it looks like incorrect behaviour to me

I modified the way of running the sample code:

MacBook-Pro-4:testcontainer-bug grzegorzszeliga$ DEBUG=testcontainers npx tsx index.ts
  testcontainers [DEBUG] Testing container runtime strategy "TestcontainersHostStrategy"... +0ms
  testcontainers [DEBUG] Testing container runtime strategy "ConfigurationStrategy"... +1ms
  testcontainers [DEBUG] Testing container runtime strategy "UnixSocketStrategy"... +0ms
  testcontainers [DEBUG] Testing container runtime strategy "RootlessUnixSocketStrategy"... +0ms
  testcontainers [DEBUG] Container runtime strategy "RootlessUnixSocketStrategy" works +236ms
  testcontainers [DEBUG] Checking if image exists "surrealdb/surrealdb:1.0.0"... +0ms
  testcontainers [DEBUG] Checked if image exists "surrealdb/surrealdb:1.0.0" +5ms
  testcontainers [DEBUG] Image "surrealdb/surrealdb:1.0.0" already exists +0ms
  testcontainers [DEBUG] Acquiring lock file "/var/folders/ln/vb7mq1fj1wq5c10gkggbs61r0000gn/T/testcontainers-node.lock"... +3ms
  testcontainers [DEBUG] Acquired lock file "/var/folders/ln/vb7mq1fj1wq5c10gkggbs61r0000gn/T/testcontainers-node.lock" +2ms
  testcontainers [DEBUG] Listing containers... +1ms
  testcontainers [DEBUG] Listed containers +4ms
  testcontainers [DEBUG] Reusing existing Reaper for session "e6d4559533f6"... +0ms
  testcontainers [DEBUG] [eabec8ba83f4] Connecting to Reaper (attempt 1) on "localhost:32770"... +0ms
  testcontainers [DEBUG] [eabec8ba83f4] Connected to Reaper +3ms
  testcontainers [DEBUG] Releasing lock file "/var/folders/ln/vb7mq1fj1wq5c10gkggbs61r0000gn/T/testcontainers-node.lock"... +0ms
  testcontainers [DEBUG] Released lock file "/var/folders/ln/vb7mq1fj1wq5c10gkggbs61r0000gn/T/testcontainers-node.lock" +0ms
  testcontainers [DEBUG] Creating container for image "surrealdb/surrealdb:1.0.0"... +0ms
  testcontainers [DEBUG] [d304b16c6186] Created container for image "surrealdb/surrealdb:1.0.0" +29ms
  testcontainers [INFO] [d304b16c6186] Starting container for image "surrealdb/surrealdb:1.0.0"... +0ms
  testcontainers [DEBUG] [d304b16c6186] Starting container... +0ms
  testcontainers [DEBUG] [d304b16c6186] Started container +141ms
  testcontainers [INFO] [d304b16c6186] Started container for image "surrealdb/surrealdb:1.0.0" +0ms
  testcontainers [DEBUG] [d304b16c6186] Inspecting container... +0ms
  testcontainers [DEBUG] [d304b16c6186] Inspected container +4ms
  testcontainers [DEBUG] [d304b16c6186] Waiting for container to be ready... +0ms
  testcontainers [DEBUG] [d304b16c6186] Waiting for host port 32772... +0ms
  testcontainers [DEBUG] [d304b16c6186] Waiting for internal port 8000... +0ms
  testcontainers [DEBUG] [d304b16c6186] Host port 32772 ready +4ms
  testcontainers [DEBUG] [d304b16c6186] Host port wait strategy complete +0ms
  testcontainers [ERROR] [d304b16c6186] The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy +93ms
  testcontainers [ERROR] [d304b16c6186] Port 8000 not bound after 60000ms +1m
  testcontainers [ERROR] [d304b16c6186] Container failed to be ready: Error: Port 8000 not bound after 60000ms +0ms
  testcontainers [DEBUG] [d304b16c6186] Stopping container... +0ms
  testcontainers [DEBUG] [d304b16c6186] Stopped container +106ms
  testcontainers [DEBUG] [d304b16c6186] Removing container... +0ms
  testcontainers [DEBUG] [d304b16c6186] Removed container +6ms
Error: Port 8000 not bound after 60000ms
    at <anonymous> (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:37:19)
    at IntervalRetry.retryUntil (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/common/retry.js:29:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at HostPortWaitStrategy.waitForPort (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:34:9)
    at HostPortWaitStrategy.waitForInternalPorts (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:29:13)
    at async Promise.all (index 1)
    at HostPortWaitStrategy.waitUntilReady (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:13:9)
    at waitForContainer (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/wait-for-container.js:8:9)
    at GenericContainer.startContainer (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/generic-container/generic-container.js:140:9)
    at main (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/index.ts:5:23)
MacBook-Pro-4:testcontainer-bug grzegorzszeliga$ 

This fragment is particularly interesting:

  testcontainers [ERROR] [d304b16c6186] The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy +93ms
  testcontainers [ERROR] [d304b16c6186] Port 8000 not bound after 60000ms +1m
  testcontainers [ERROR] [d304b16c6186] Container failed to be ready: Error: Port 8000 not bound after 60000ms +0ms

When I don't raise the logging level, I don't see the information that the waiting strategy on this platform is not working:

MacBook-Pro-4:testcontainer-bug grzegorzszeliga$ npx tsx index.ts
Error: Port 8000 not bound after 60000ms
  at <anonymous> (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:37:19)
  at IntervalRetry.retryUntil (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/common/retry.js:29:24)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at HostPortWaitStrategy.waitForPort (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:34:9)
  at HostPortWaitStrategy.waitForInternalPorts (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:29:13)
  at async Promise.all (index 1)
  at HostPortWaitStrategy.waitUntilReady (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/host-port-wait-strategy.js:13:9)
  at waitForContainer (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/wait-strategies/wait-for-container.js:8:9)
  at GenericContainer.startContainer (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/node_modules/testcontainers/build/generic-container/generic-container.js:140:9)
  at main (/Users/grzegorzszeliga/Desktop/notatki_main/testcontainer-bug/index.ts:5:23)

It would be great if all error-related information appeared on the user's console, even when the error reporting level is not raised.

@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Dec 1, 2023

I don't assume anything. I am learning the tool. I made a ticket because it looks like incorrect behaviour to me

I didn't say you assume, I said I assume 😄

Looks like I correctly assumed it's an issue with the way you're starting the container - because the image is distroless you'll need to configure an alternate wait strategy. You can find more info in the docs: https://node.testcontainers.org/features/wait-strategies/

I will raise a separate issue to improve error logging. Thanks!

@szagi3891
Copy link
Author

szagi3891 commented Dec 1, 2023

Thank you. The improved logs will be very useful :)

because the image is distroless

What does it mean ?

@cristianrgreco
Copy link
Collaborator

because the image is distroless

What does it mean ?

Distroless images contain only your application and its runtime dependencies. They do not contain package managers, shells or any other programs you would expect to find in a standard Linux distribution. More info here: https://github.com/GoogleContainerTools/distroless#distroless-container-images

This is an issue for you because the default wait strategy runs some shell commands to see if a port is bound, but no shell is available. You could therefore use alternate wait strategies, for example LogWaitStrategy or HttpWaitStrategy, which don't require a shell.

@szagi3891
Copy link
Author

Thank you very much for the explanations. This HttpWaitStrategy strategy seems very interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants