karatelabs/karate · error · RuntimeException

Interrupted while waiting for driver

Error message

Interrupted while waiting for driver

What it means

The thread waiting in waitForDriver on availableDrivers.poll(30, TimeUnit.SECONDS) was interrupted. The code restores the interrupt flag and rethrows as a RuntimeException. This is almost never a browser/driver problem — something interrupted the test thread while it waited for a pooled driver.

Solutions

  1. Find what interrupts the thread (executor shutdown, framework timeout) and delay that until all scenarios finish
  2. Ensure shutdown/teardown hooks run only after all acquire() calls complete
  3. Increase the build/framework timeout so the run isn't cancelled mid-wait
  4. Check for competing shutdown code in your own test harness that calls executorService.shutdownNow() prematurely

Example fix

// before: shutdownNow while scenarios still queued
executor.submit(() -> runner.run());
executor.shutdownNow(); // interrupts waiting acquire()
// after: wait for completion first
executor.submit(() -> runner.run());
executor.shutdown();
executor.awaitTermination(10, TimeUnit.MINUTES); // no interrupt while waiting
Defensive patterns

Strategy: try-catch

Validate before calling

// avoid interrupting worker threads: check executor state before submission
if (executor.isShutdown()) { throw new IllegalStateException("executor already shut down"); }

Type guard

null

Try / catch

try { Driver d = provider.acquire(runtime, config); }
catch (RuntimeException e) {
    if (e.getCause() instanceof InterruptedException) {
        Thread.currentThread().interrupt(); // preserve flag, abort gracefully
        return;
    }
    throw e;
}

Prevention

When it happens

Trigger: Executor/executor-service shutdown during a running suite; JUnit/TestNG or Surefire cancelling the run (timeout, Ctrl-C, fail-fast); another component calling Thread.interrupt() on the Karate thread while it blocks in acquire().

Common situations: Build tool timeout killing the forked JVM mid-run; a plugin shutting down its thread pool while scenarios are queued; mis-behaving parallel test frameworks interrupting worker threads at teardown; graceful-shutdown paths racing with in-flight acquire().

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/3d47477592488075. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/driver/PooledDriverProvider.java:223

            // handed out to the next scenario.
            if (driver.isTerminated()) {
                createdCount.decrementAndGet();
                driver = createDriver(config);
                createdCount.incrementAndGet();
                logger.info("Replaced terminated driver for scenario: {}", scenarioName);
            } else if (!resetDriver(driver)) {
                closeDriverQuietly(driver);
                createdCount.decrementAndGet();
                driver = createDriver(config);
                createdCount.incrementAndGet();
                logger.info("Replaced unhealthy driver for scenario: {}", scenarioName);
            } else {
                logger.info("Acquired pooled driver after wait for scenario: {}", scenarioName);
            }
            return driver;
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException("Interrupted while waiting for driver", e);
        }
    }

    @Override
    public void release(ScenarioRuntime runtime, Driver driver) {
        assignedDrivers.remove(runtime);

        if (shutdown) {
            // During shutdown, just close the driver
            closeDriverQuietly(driver);
            return;
        }

        if (driver.isTerminated()) {
            logger.debug("Not returning terminated driver to pool");
            createdCount.decrementAndGet();
            return;
        }

View on GitHub (pinned to a22eb90246)