{"record":{"id":"d2ee41db21938279","repo":"karatelabs/karate","slug":"listen-timed-out-after-timeoutms-ms","errorCode":null,"errorMessage":"listen timed out after <timeoutMs>ms","messagePattern":"listen timed out after <timeoutMs>ms","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java","lineNumber":2482,"sourceCode":"    public void setListenResult(Object result) {\n        this.listenResult = result;\n        this.listenLatch.countDown();\n    }\n\n    /**\n     * Wait for a signal with timeout.\n     * Returns the signaled result or throws on timeout.\n     */\n    public Object waitForListenResult(long timeoutMs) {\n        try {\n            if (listenLatch.await(timeoutMs, TimeUnit.MILLISECONDS)) {\n                Object result = listenResult;\n                // Reset for potential reuse\n                listenResult = null;\n                listenLatch = new CountDownLatch(1);\n                return result;\n            }\n            throw new RuntimeException(\"listen timed out after \" + timeoutMs + \"ms\");\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new RuntimeException(\"listen interrupted\", e);\n        }\n    }\n\n    /**\n     * Get the current listen result without waiting.\n     */\n    public Object getListenResult() {\n        return listenResult;\n    }\n\n    // ========== Performance Testing (Gatling Integration) ==========\n\n    /**\n     * Check if performance mode is enabled.\n     * When true, HTTP request timing is reported via PerfHook.","sourceCodeStart":2464,"sourceCodeEnd":2500,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java#L2464-L2500","documentation":"The `listen` keyword pauses the scenario until external code (e.g. a mock server or browser callback) supplies a result via listenResult. If nothing arrives within the configured timeout, the CountDownLatch await expires and the runtime throws \"listen timed out after <timeoutMs>ms\".","triggerScenarios":"`* listen <timeout> someVariable` where no callback invokes karate.signal(listenKey) / sets the listen result before timeoutMs elapses.","commonSituations":"OAuth/browser redirect flows where the external service never calls back; mock server not started or listening on the wrong port; async JS in the browser not triggering the result; timeout too short for a slow environment.","solutions":["Verify the code paired with listen actually calls `karate.signal(result)` (or the listen server posts the result) and that it is running","Increase the listen timeout, e.g. `* listen 30000 result` for slow environments","Check ports/firewalls and callback URLs so the external side can reach the listener; add logging on the callback path"],"exampleFix":"// before\n* listen 5000 token   // times out in slow CI\n// after\n* listen 60000 token","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { karate.listen(60000, 'token'); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"listen timed out\")) { /* check callback fired / increase timeout */ } throw e; }","preventionTips":["Pair every listen with code that definitely calls karate.signal(result)","Start the mock server/listener before the listen step and verify its port is reachable","Use generous timeouts in CI and add logging on the callback path"],"tags":["listen","timeout","async"],"backgroundTag":"request-timeout","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"}