{"record":{"id":"78b89a2a8a13fd5b","repo":"karatelabs/karate","slug":"could-not-detect-pool-size-defaulting-to-1","errorCode":null,"errorMessage":"Could not detect pool size, defaulting to 1","messagePattern":"Could not detect pool size, defaulting to 1","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/driver/PooledDriverProvider.java","lineNumber":187,"sourceCode":"    }\n\n    private void ensurePoolInitialized(ScenarioRuntime runtime) {\n        if (availableDrivers != null) {\n            return;\n        }\n        synchronized (initLock) {\n            if (availableDrivers != null) {\n                return;\n            }\n            // Auto-detect pool size from Suite's threadCount\n            if (poolSize < 1 && runtime.getFeatureRuntime() != null\n                    && runtime.getFeatureRuntime().getSuite() != null) {\n                poolSize = runtime.getFeatureRuntime().getSuite().threadCount;\n                logger.info(\"Auto-detected pool size from Suite: {}\", poolSize);\n            }\n            if (poolSize < 1) {\n                poolSize = 1;  // Fallback\n                logger.warn(\"Could not detect pool size, defaulting to 1\");\n            }\n            availableDrivers = new ArrayBlockingQueue<>(poolSize);\n        }\n    }\n\n    private Driver waitForDriver(Map<String, Object> config, ScenarioRuntime runtime) {\n        String scenarioName = runtime.getScenario().getName();\n        logger.warn(\"Pool exhausted for scenario '{}', waiting for available driver... [{}]\",\n                scenarioName, getStats());\n        try {\n            Driver driver = availableDrivers.poll(30, TimeUnit.SECONDS);\n            if (driver == null) {\n                throw new RuntimeException(\"Timeout waiting for available driver for scenario '\"\n                        + scenarioName + \"' [\" + getStats() + \"]\");\n            }\n            // If the driver is terminated OR fails reset/liveness, replace it.\n            // Same rationale as takeHealthyFromPool — a poisoned driver must not be\n            // handed out to the next scenario.","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/PooledDriverProvider.java#L169-L205","documentation":"PooledDriverProvider lazily creates its driver pool on first acquire(). It determines the pool size from an explicit config value or by auto-detecting the Suite's threadCount; if neither yields a size >= 1, it logs this warning and falls back to a pool of 1, which serializes all driver acquisition and can slow parallel UI tests.","triggerScenarios":"acquire() is called and poolSize is still < 1: no maxPoolSize/driver pool-size config option set AND runtime.getFeatureRuntime().getSuite() is null or its threadCount is 0/unset (e.g. driver used outside a normal parallel Suite context).","commonSituations":"Chrome/chrome-headless drivers used with default options in a Suite whose threadCount was not propagated; driver acquired in a unit-test or embedded runtime without a Suite; pool-size property misspelled so it never gets read.","solutions":["Set the pool size explicitly, e.g. -Dkarate.driver.poolSize=N or the driver pool config option, so auto-detection is unnecessary","Run with Runner / threadCount set (e.g. -T 4 with Maven surefire or Runner.Builder.threadCount) so the Suite auto-detection path works","Verify the config key spelling for pool size in karate-config.js","Accept the pool of 1 only for debugging; for parallel UI suites, size the pool to match threadCount"],"exampleFix":"// before: no pool size, no thread count\nRunner.path(classpath(\"ui/features\"));\n// after: parallel run so pool auto-detects threadCount\nRunner.path(classpath(\"ui/features\")).threadCount(4);","handlingStrategy":"validation","validationCode":"// before the run, ensure threadCount is set so pool auto-detection works\nint threads = suite.getThreadCount();\nif (threads < 1) throw new IllegalStateException(\"set -T / threadCount so the driver pool can be sized\");","typeGuard":"Integer poolSize = System.getProperty(\"karate.driver.poolSize\") != null\n    ? Integer.valueOf(System.getProperty(\"karate.driver.poolSize\"))\n    : (suite != null && suite.threadCount > 0 ? suite.threadCount : null); // null => pool of 1 warning","tryCatchPattern":null,"preventionTips":["Always run UI suites with an explicit threadCount (Runner.Builder.threadCount or Maven -T)","Set the driver pool-size config explicitly when embedding Karate or using drivers outside a Suite","Keep the pool size >= threadCount so parallel scenarios never wait on drivers","Watch startup logs for 'Auto-detected pool size from Suite' to confirm sizing worked"],"tags":["driver","pooling","configuration"],"backgroundTag":"invalid-config-value","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"}