testcontainers/testcontainers-java · error · ContainerLaunchException

Timed out waiting for log output matching

Error message

Timed out waiting for log output matching '%s'

What it means

LogMessageWaitStrategy watches container stdout/stderr for a line matching a configured regex (withRegEx) and throws ContainerLaunchException when no matching log message appears within the startup timeout. It means the container ran but never printed the expected 'ready' marker.

Solutions

  1. Print container.getLogs() and adjust the regex in .withRegEx(...) to match the real output
  2. Increase .withStartupTimeout(Duration.ofSeconds(120))
  3. Confirm the app logs the ready message to stdout/stderr, not a log file
  4. Check the container didn't crash-loop — look for exit codes/restarts in logs

Example fix

// before
new LogMessageWaitStrategy().withRegEx(".*Server started.*").withStartupTimeout(Duration.ofSeconds(30));
// after
new LogMessageWaitStrategy().withRegEx(".*Started .*Application in .*\\n").withStartupTimeout(Duration.ofSeconds(90));
Defensive patterns

Strategy: retry

Validate before calling

// Confirm the app emits the marker to stdout before waiting on logs
String logs = container.getLogs();
if (!logs.matches("(?s).*Started .*Application.*")) {
    System.out.println("No ready marker yet; current logs: " + logs);
}

Try / catch

try {
    container.waitingFor(new LogMessageWaitStrategy().withRegEx(".*ready.*\\n")).start();
} catch (ContainerLaunchException e) {
    if (e.getMessage().startsWith("Timed out waiting for log output matching")) {
        System.err.println("Container logs: " + container.getLogs());
    }
    throw e;
}

Prevention

When it happens

Trigger: waitUntilReady calls waitingConsumer.waitUntil(predicate, startupTimeout) and a TimeoutException is raised because no output frame matches '(?s)' + regEx before the timeout.

Common situations: Regex doesn't match the app's actual log format (log format changed between versions); app logs the message to a file instead of stdout; app failed to start entirely; startup timeout too short for slow apps.

Understand the failure class

Related errors


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/c067037223e033fd. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/testcontainers/containers/wait/strategy/LogMessageWaitStrategy.java:47

            .withFollowStream(true)
            .withSince(0)
            .withStdOut(true)
            .withStdErr(true);

        try (FrameConsumerResultCallback callback = new FrameConsumerResultCallback()) {
            callback.addConsumer(OutputFrame.OutputType.STDOUT, waitingConsumer);
            callback.addConsumer(OutputFrame.OutputType.STDERR, waitingConsumer);

            cmd.exec(callback);

            Predicate<OutputFrame> waitPredicate = outputFrame -> {
                // (?s) enables line terminator matching (equivalent to Pattern.DOTALL)
                return outputFrame.getUtf8String().matches("(?s)" + regEx);
            };
            try {
                waitingConsumer.waitUntil(waitPredicate, startupTimeout.getSeconds(), TimeUnit.SECONDS, times);
            } catch (TimeoutException e) {
                throw new ContainerLaunchException("Timed out waiting for log output matching '" + regEx + "'");
            }
        }
    }

    public LogMessageWaitStrategy withRegEx(String regEx) {
        this.regEx = regEx;
        return this;
    }

    public LogMessageWaitStrategy withTimes(int times) {
        this.times = times;
        return this;
    }
}

View on GitHub (pinned to 8e549514e3)