{"record":{"id":"d6402939f07bb0b9","repo":"karatelabs/karate","slug":"error-resetting-driver-state-will-discard","errorCode":null,"errorMessage":"Error resetting driver state, will discard: {}","messagePattern":"Error resetting driver state, will discard: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/driver/PooledDriverProvider.java","lineNumber":390,"sourceCode":"            if (dialog != null) {\n                logger.debug(\"Dismissing stale dialog before reset\");\n                try {\n                    dialog.dismiss();\n                } catch (Exception e) {\n                    logger.debug(\"Dialog dismiss during reset (may already be handled): {}\", e.getMessage());\n                }\n            }\n            driver.setUrl(\"about:blank\");\n            driver.clearCookies();\n            // Barrier on readiness before reuse: setUrl(\"about:blank\") returns early\n            // (about: URLs skip waitForPageLoad), so the fresh execution context may\n            // still be settling. waitUntilReady() blocks until it is live so the next\n            // scenario's first call never races a not-yet-ready context. No-op on\n            // backends that establish readiness synchronously.\n            driver.waitUntilReady();\n        } catch (Exception e) {\n            // Reset itself failed — channel is already sick (setUrl timeout, websocket closed, etc.)\n            logger.warn(\"Error resetting driver state, will discard: {}\", e.getMessage());\n            return false;\n        }\n        // Post-reset liveness probe. setUrl(\"about:blank\") can succeed on a driver that\n        // will still hang on the next http:// navigation (seen after tab-switch.feature —\n        // about:blank is local so Chrome handles it even when network-facing navigation\n        // is stuck). A bounded Runtime.evaluate catches the degraded state before we\n        // return the driver to the pool.\n        if (!driver.isResponsive()) {\n            logger.warn(\"Driver failed post-reset liveness probe, will discard\");\n            return false;\n        }\n        return true;\n    }\n\n    /**\n     * Create a new driver from config.\n     * Subclasses should override for custom driver creation (e.g., Testcontainers).\n     * <p>","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/PooledDriverProvider.java#L372-L408","documentation":"resetDriver() prepares a pooled driver for the next scenario (navigating to about:blank, waitUntilReady, etc.). If any of those reset steps throw, the driver's channel is already sick, so the pool logs this and returns false meaning 'discard this driver'. This prevents recycling a driver whose websocket died or timed out.","triggerScenarios":"setUrl timeout, closed websocket, or any exception thrown during driver.reset() / waitUntilReady() when re-borrowing a pooled driver via takeHealthyFromPool() or waitForDriver().","commonSituations":"Browser tab crashed between scenarios; Chrome DevTools channel dropped after idle; network-stack wedge making even about:blank navigation hang then timeout.","solutions":["No caller action needed — pool discards and creates a fresh driver; verify createdCount grows to poolSize","If it happens every cycle, fix the underlying browser instability (memory, zombie chrome processes)","Ensure waitUntilReady-compatible backends; update to a driver build with bounded readiness checks"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-borrow sanity check\nif (driver.isTerminated() || !driver.isResponsive()) { /* force discard + reborrow */ }","typeGuard":null,"tryCatchPattern":"boolean ok = pool.resetDriver(driver, runtime);\nif (!ok) { driver = pool.acquire(options, runtime); } // pool discards internally","preventionTips":["Keep browsers healthy (memory, no zombie processes)","Avoid leaving scenarios mid-navigation when they end","Recycle drivers periodically instead of reusing indefinitely"],"tags":["driver-pool","driver-reset","cdp","browser-crash"],"backgroundTag":"broken-pipe","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}