{"record":{"id":"b7a7093ff054a842","repo":"karatelabs/karate","slug":"interrupted-while-publishing-test-event","errorCode":null,"errorMessage":"Interrupted while publishing test event","messagePattern":"Interrupted while publishing test event","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-junit6/src/main/java/io/karatelabs/junit6/JUnitBridgeListener.java","lineNumber":103,"sourceCode":"     * Deliberately <em>not</em> driven by {@link #onSuiteEnd(SuiteResult)}: that callback\n     * fires while the suite is still running its listener chain, so report writers (JUnit\n     * XML, Cucumber JSON) registered after this bridge may not have flushed their\n     * asynchronous per-feature writes yet. Emitting the terminal event from here — invoked\n     * only once {@code Runner.Builder.parallel(...)} has fully returned — guarantees that\n     * when the JUnit {@code @TestFactory} stream completes, all report files are on disk.\n     *\n     * @param result the suite result (may be null if execution failed before completing)\n     */\n    public void complete(SuiteResult result) {\n        putEvent(new TestEvent.SuiteEnd(result));\n    }\n\n    private void putEvent(TestEvent event) {\n        try {\n            eventQueue.put(event);\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new RuntimeException(\"Interrupted while publishing test event\", e);\n        }\n    }\n\n}\n","sourceCodeStart":85,"sourceCodeEnd":108,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-junit6/src/main/java/io/karatelabs/junit6/JUnitBridgeListener.java#L85-L108","documentation":"JUnitBridgeListener queues test events (feature start/end, scenario end, completion) onto a blocking queue for the JUnit streamer to consume. If the publishing thread is interrupted while blocking on the queue, the listener restores the interrupt flag and rethrows as a RuntimeException.","triggerScenarios":"The thread calling putEvent (via onFeatureStart/onFeatureEnd/onScenarioEnd/complete) is interrupted while the event queue is full or the JVM is shutting down.","commonSituations":"Build cancellation (Ctrl+C in Maven/Gradle), test timeouts that interrupt worker threads, executor shutdown while a feature is still reporting.","solutions":["Let the JVM shutdown proceed; this error usually signals an external interruption, not a bug","Check for build/test timeouts that interrupt the reporting thread and raise them","Ensure no custom code shuts down the executor/threads while Karate features are still running"],"exampleFix":"// build config before\n<timeout>30</timeout>\n// after\n<timeout>300</timeout> <!-- allow long feature runs to finish -->","handlingStrategy":"try-catch","validationCode":"// before shutdown, ensure reporting has drained\nboolean idle = bridgeListener != null && bridgeListener.isIdle();","typeGuard":"null","tryCatchPattern":"try {\n  runKarateSuite();\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Interrupted while publishing test event\")) {\n    Thread.interrupted(); // acknowledge and continue shutdown\n    return;\n  }\n  throw e;\n}","preventionTips":["Avoid cancelling builds mid-feature when possible","Do not interrupt executor threads that run Karate features","Grant generous build timeouts so reporting completes"],"tags":["junit","concurrency","interruption","threading"],"backgroundTag":"thread-interrupted","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"}