{"record":{"id":"d8d9cb95964b4d9f","repo":"testcontainers/testcontainers-java","slug":"expiry-time-reached-before-end-of-output","errorCode":null,"errorMessage":"Expiry time reached before end of output","messagePattern":"Expiry time reached before end of output","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/output/WaitingConsumer.java","lineNumber":157,"sourceCode":"\n    private void waitUntilEnd(Long expiry) throws TimeoutException {\n        while (System.nanoTime() < expiry) {\n            try {\n                OutputFrame frame = frames.pollLast(100, TimeUnit.MILLISECONDS);\n\n                if (frame == OutputFrame.END) {\n                    return;\n                }\n\n                if (frames.isEmpty()) {\n                    // sleep for a moment to avoid excessive CPU spinning\n                    Thread.sleep(10L);\n                }\n            } catch (InterruptedException e) {\n                throw new RuntimeException(e);\n            }\n        }\n        throw new TimeoutException(\"Expiry time reached before end of output\");\n    }\n}\n","sourceCodeStart":139,"sourceCodeEnd":160,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/output/WaitingConsumer.java#L139-L160","documentation":"WaitingConsumer.waitUntilEnd() polls the container's log stream until the end is reached or the given expiry (timeout Duration) elapses. If no end-of-output is detected before the deadline it throws a TimeoutException. This means output kept flowing (or the stream never terminated) within the allotted time.","triggerScenarios":"`waitingConsumer.waitUntilEnd(timeout, ...)` while the container keeps producing output indefinitely, or frames stop but no explicit end condition matches, until the expiry passes.","commonSituations":"Waiting for a container whose logs keep printing (e.g. tail -f style apps), using waitUntilEnd on a long-running service rather than a batch job, timeout set shorter than the container's startup output burst.","solutions":["Increase the timeout Duration passed to waitUntilEnd().","Use waitUntil(frame -> predicate) with a specific expected line instead of waiting for end-of-output.","Ensure the target container actually terminates if end-of-output is what you need.","Add a `waitUntilEnd` only for batch-style containers that exit."],"exampleFix":"// before\nwaitingConsumer.waitUntilEnd(Duration.ofSeconds(5), TimeUnit.SECONDS);\n// after: wait for a specific log line instead\nwaitingConsumer.waitUntil(frame -> frame.getUtf8String().contains(\"Started Application\"), 30, TimeUnit.SECONDS);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { waitingConsumer.waitUntilEnd(60, TimeUnit.SECONDS); } catch (TimeoutException e) { log.warn(\"container output did not end in time; logs so far: {}\", container.getLogs()); }","preventionTips":["Use waitUntil(predicate) for long-running containers instead of waitUntilEnd.","Reserve waitUntilEnd for containers expected to terminate (batch jobs).","Set timeouts generously relative to app startup time."],"tags":["timeout","log-waiting","container-logs"],"backgroundTag":"request-timeout","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}