{"record":{"id":"6a530dd494f083fb","repo":"karatelabs/karate","slug":"timeout-waiting-for-stream-readers-this-should-not-happen","errorCode":null,"errorMessage":"timeout waiting for stream readers - this should not happen","messagePattern":"timeout waiting for stream readers - this should not happen","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/process/ProcessHandle.java","lineNumber":366,"sourceCode":"    /**\n     * Wait for all stream reader threads to complete.\n     * This ensures all output is captured before getStdOut()/getStdErr() is called.\n     * <p>\n     * After process exit, stream readers complete almost instantly since the OS\n     * closes the pipes. We use a short timeout as a safety net.\n     */\n    private void waitForStreamReaders() {\n        try {\n            // Streams close immediately after process exit, so this should be near-instant.\n            // Use 500ms timeout as safety net (never hit in practice).\n            if (stdoutReaderDone != null && !stdoutReaderDone.isDone()) {\n                stdoutReaderDone.get(500, TimeUnit.MILLISECONDS);\n            }\n            if (stderrReaderDone != null && !stderrReaderDone.isDone()) {\n                stderrReaderDone.get(500, TimeUnit.MILLISECONDS);\n            }\n        } catch (TimeoutException e) {\n            logger.warn(\"timeout waiting for stream readers - this should not happen\");\n        } catch (Exception e) {\n            logger.debug(\"error waiting for stream readers: {}\", e.getMessage());\n        }\n    }\n\n    /**\n     * Wait until predicate returns true for an output line.\n     *\n     * @param predicate Test function that receives the line\n     * @return The line that matched\n     */\n    public String waitForOutput(Predicate<String> predicate) {\n        return waitForOutput(predicate, 0);\n    }\n\n    /**\n     * Wait until predicate returns true for an output line, with timeout.\n     *","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/process/ProcessHandle.java#L348-L384","documentation":"When a process handle's `waitSync` finishes waiting on the process, it gives each stream-reader future a short 500ms window to complete. If a reader still hasn't finished after that, this warning is logged. It indicates the stdout/stderr pump threads are unexpectedly stuck and output may not have been fully drained.","triggerScenarios":"A child process's stdout or stderr pipe remains open after process exit — typically because a grandchild inherited the pipe and is still running; extremely large buffered output not yet consumed within 500ms.","commonSituations":"Spawning scripts that launch background children which inherit the streams; daemon threads of the child still writing after main exit; pipe buffer back-pressure due to a reader that stopped consuming.","solutions":["Ensure child processes redirect their own output (e.g. redirect grandchildren to files or /dev/null)","Check for orphaned grandchildren keeping the pipe open and kill them","Drain streams promptly so pump threads never block on back-pressure","Treat as diagnostic: investigate why output did not finish shortly after process exit"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { handle.waitSync(); }\ncatch (Exception e) { log.warn(\"process teardown issue\", e); } // the warn inside is the real signal: check for orphaned grandchildren","preventionTips":["Redirect child subprocess output away from inherited pipes","Ensure no grandchildren inherit stdout/stderr","Consume streams continuously to avoid pipe back-pressure"],"tags":["process","io","streams","lifecycle"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}