{"record":{"id":"960dcc710b408679","repo":"karatelabs/karate","slug":"failed-to-close-jsonl-event-stream","errorCode":null,"errorMessage":"Failed to close JSONL event stream: {}","messagePattern":"Failed to close JSONL event stream: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/core/Suite.java","lineNumber":603,"sourceCode":"            // Fire SUITE_EXIT event\n            fireEvent(SuiteRunEvent.exit(this, result));\n        } finally {\n            if (result.getEndTime() == 0) {\n                result.setEndTime(System.currentTimeMillis());\n            }\n\n            // Shutdown driver provider if one exists\n            if (driverProvider != null) {\n                driverProvider.shutdown();\n            }\n\n            // Close JSONL event writer\n            if (jsonlWriter != null) {\n                try {\n                    removeJsonlListener(jsonlWriter);\n                    jsonlWriter.close();\n                } catch (Exception e) {\n                    logger.warn(\"Failed to close JSONL event stream: {}\", e.getMessage());\n                }\n            }\n\n            // Ext onShutdown — best-effort; exceptions are logged + dropped per K43.\n            if (bootBinding != null) {\n                for (Ext ext : bootBinding.getExts()) {\n                    try {\n                        ext.onShutdown();\n                    } catch (Exception e) {\n                        logger.warn(\"ext onShutdown failed ({}): {}\",\n                                ext.getClass().getName(), e.getMessage());\n                    }\n                    removeJsonlListener(ext);\n                }\n            }\n\n            // Notify listeners\n            for (ResultListener listener : resultListeners) {","sourceCodeStart":585,"sourceCodeEnd":621,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/Suite.java#L585-L621","documentation":"At the end of Suite.run(), the JSONL event writer is removed from the listener list and closed. If closing the underlying stream throws (IO error flushing final bytes, stream already closed by something else), the warning is logged and shutdown continues — the suite result is unaffected, but the JSONL file may be truncated.","triggerScenarios":"Suite.run() teardown where jsonlWriter.close() throws: disk became full while flushing the final buffer, underlying file handle already closed, filesystem error on the output volume, or an OS-level IO failure.","commonSituations":"CI agents unmounting volumes mid-teardown; two Suite instances sharing an output dir so one closes the file first; disk-quota exhaustion during a large run.","solutions":["Verify the JSONL file is complete/parseable; if truncated, re-run with more disk headroom","Ensure only one Suite owns the output directory and its event writer","Check for disk-full or quota errors on the output volume around test end time","If only the warning appears and results are correct, it is safe to ignore the truncated event stream"],"exampleFix":"// before: two suites writing the same dir in one JVM\nSuite a = new Suite(opts with outputDir \"target/karate\");\nSuite b = new Suite(opts with outputDir \"target/karate\");\n// after: distinct output dirs per suite\nSuite a = new Suite(opts with outputDir \"target/karate-a\");\nSuite b = new Suite(opts with outputDir \"target/karate-b\");","handlingStrategy":"try-catch","validationCode":"// after the run, verify the JSONL file ends with a complete line\njava.nio.file.Path f = java.nio.file.Path.of(outputDir, \"karate-events.jsonl\");\nString tail = java.nio.file.Files.readString(f).stripTrailing();\nif (!tail.endsWith(\"}\")) throw new IllegalStateException(\"JSONL stream truncated (close failed?)\");","typeGuard":null,"tryCatchPattern":"try {\n    suite.run();\n} finally {\n    // Suite already warns on close failure; validate the artifact\n    if (!isCompleteJsonl(outputDir)) logger.warn(\"JSONL event file incomplete — treat as best-effort\");\n}","preventionTips":["Give each Suite its own output directory so writers never share file handles","Ensure enough disk space for the full event log (large runs write a lot)","Avoid unmounting/tearing down CI workspace volumes before the JVM exits","Treat JSONL as best-effort telemetry; never depend on it for pass/fail assertions"],"tags":["io","events","cleanup"],"backgroundTag":"file-write-failed","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"}