Skip to content
Commit Detail

Commit d3dfab5

Author
James M Snell <jsnell@cloudflare.com> 2026-02-22 11:03:22 -0800
Parents
31c07ba
Tree
a99908c
Flush pending microtasks on service worker startup

Service-worker format scripts (non-module) did not
flush the V8 microtask queue after top-level
evaluation in the Worker constructor.

When two Workers sharing an isolate (same script,
different zones) are constructed sequentially,
and leave pending microtasks on the shared
per-isolate queue, the first request's microtask
checkpoint will then drain microtasks from both
contexts, executing the other Worker's callbacks
under the wrong IoContext — causing things like
`TimeoutId::Generator`` mismatch assertions and
potential cross-context state corruption.

The fix is to call `lock.runMicrotasks()` after
`NonModuleScript::run()`, matching the module path.

A test in workerd (either C++ or wd-test) is currently
not possible so the regression test will be added
to the internal project.

Files changed

1 file changed~1 modified