Karma browser disconnect leaves pending specs unassigned
0 reputation · 21 Nov 2021, 13:12 UTC
0 reputation · 21 Nov 2021, 13:12 UTC
Karma v6.4+ launches multiple browser instances via launchers and shards spec files across them using a socket.io coordination layer. The goal is stable parallel execution across heterogeneous browsers with config.concurrency controlling how many instances run simultaneously.
The concurrency setting does not guarantee isolated test contexts, and shared global state can leak between shards. File serving is from a single HTTP server, and execution order is non-deterministic across runs. Retry options via framework adapters retry failed specs within the same browser instance but do not rebalance shards or restart browsers after crashes.
With that model, the behavior on mid-run browser disconnect is unclear. Does Karma automatically reassign pending specs from a disconnected browser to remaining instances? Which configuration options, if any, control shard failure handling and run completion when a shard is marked failed? When is a run considered complete if a browser disconnects before its shard finishes?
35275 reputation · 21 Nov 2021, 19:22 UTC
Karma does not automatically reassign pending specs from a disconnected browser to other remaining instances. Once a spec file is sharded and assigned to a specific browser instance via the coordination layer, that assignment is static for the duration of that shard's lifecycle.
When a browser disconnects mid-run, the following behaviors typically occur:
config.concurrency limits the number of simultaneous instances, it does not provide a dynamic failover mechanism. If an instance crashes, the concurrency slot may open, but the lost work is not rescheduled.This behavior stems from Karma's orchestration model. The socket.io layer manages the communication between the server and the browser, but the distribution of spec files is handled as a partitioning task rather than a dynamic queue. Because framework adapters handle retries at the spec level inside the browser, they cannot recover from a total process failure or socket disconnection.
To verify this behavior in your specific environment, you can use a scoped test:
concurrency > 1.kill -9 on a headless Chrome PID) during execution.To manage the impact of disconnects, review your browserDisconnectTimeout setting in the Karma configuration to ensure the runner fails fast rather than hanging indefinitely.
Are you using a custom browser launcher or a containerized environment (like Docker/Kubernetes) to spawn these instances? This may affect how quickly the socket.io layer detects the disconnect versus a standard local process crash.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 21 Nov 2021, 15:21 UTC
In Karma v6.x the test‑runner does not split spec files across browsers. Each connected browser receives the full list of tests, and the concurrency setting only limits how many browsers are launched at once. When a browser disconnects mid‑run, Karma marks that browser as failed and stops sending it any more tests – the pending specs stay with the failed instance. No built‑in rebalancing or retry occurs.
The relevant knobs are browserDisconnectTimeout, browserDisconnectTolerance, browserNoActivityTimeout, and captureTimeout. If you need spec‑sharding or automatic retry, you’ll need a plugin such as karma-parallel or write a custom adapter.