Skip to content

wasmtime host: peer-connection drivers never share the embedder's runtime - #159

Merged
lann merged 1 commit into
mainfrom
driver-reactor-isolation
Aug 14, 2026
Merged

wasmtime host: peer-connection drivers never share the embedder's runtime#159
lann merged 1 commit into
mainfrom
driver-reactor-isolation

Conversation

@lannbot

@lannbot lannbot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #158.

One builder call plus a constant: every peer-connection driver now runs on webrtc's dedicated reactor pool (with_dedicated_reactor_pool_size(2)) instead of the embedder's ambient runtime, so a stalled or spinning driver costs a pool thread rather than the host.

Why now: wosh's freeze drill (SIGSTOP a connected peer 45s) hit a sans-IO core bug — lann/rtc#2, a failed ICE agent pinning its wake-up deadline in the past — that span the driver at ~4.5M loop passes/s. On the shared runtime that froze the embedding wasm component solid and starved the teardown that would have ended the spin (the owner never ran, never dropped the connection, so the driver's closing check never fired). Details and instrumentation on the issue.

Verified against the live bug (deliberately unfixed webrtc pin), driving the full wosh listener natively: through the 45s freeze the embedder stays responsive — the zombie session idle-times-out and parks on schedule, fresh dials are accepted mid-wedge — and the spin self-heals within seconds (busy-thread count returns to zero) because the still-running owner drops the connection. Thawed peer then resumes its session cleanly. just check green.

Residual: while a driver spins, other drivers pinned to the same pool thread stall until the self-heal; two threads bound the cost while keeping one wedge from pausing every other connection. This stays correct — and keeps webrtc#101's throughput-isolation property — after the root fix lands upstream, so it is defense-in-depth rather than a revert-later shim.

The regression test asserts the pool is actually engaged (a webrtc-rx reactor thread appears once a connection is built): the engagement is one easily-lost builder call, and nothing else observes it. Verified to bite (fails in ~10s with the pool disabled).

…time

Every driver now runs on webrtc's dedicated reactor pool
(with_dedicated_reactor_pool_size: a bounded set of single-threaded
runtimes on their own OS threads, drivers pinned round-robin, I/O
bound to the pool thread) instead of the ambient tokio runtime.

A driver is a third-party event loop; on the shared runtime it held
the whole embedder hostage. Observed live from wosh's freeze drill:
a sans-IO core bug (lann/rtc#2 -- a failed ICE agent pins its wake-up
deadline in the past) span the driver at ~4.5M loop passes/s once a
frozen peer's connection failed, starving the embedding wasm
component -- endpoint deaf, zombie sessions never idle-timed-out --
and starving the very teardown that would have ended the spin: the
resource owner never ran, never dropped the connection, so the
driver's closing check never fired.

On the pool, the same wedge costs a pool thread and then heals
itself: the owner keeps running, observes the failure, drops the
connection, and the closing check ends the loop. Verified against
the live bug (unfixed webrtc pin): the embedder stays responsive
through the freeze, sessions park on schedule, new dials are
accepted mid-wedge, and the spinning thread goes quiet within
seconds. A pool of two bounds the thread cost while keeping one
wedged driver from pausing every other connection's driver.

The regression test asserts the pool is actually engaged (a
webrtc-rx reactor thread exists once a connection is built) -- the
engagement is one easily-lost builder call, and nothing else
observes it.

Fixes #158.
@lann
lann merged commit f703a15 into main Aug 14, 2026
4 checks passed
@lann
lann deleted the driver-reactor-isolation branch August 14, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wasmtime host shares fate with the webrtc driver tasks: one wedged peer connection freezes the whole embedder

2 participants