fix: await worker-thread termination on stop/close (fixes in-process WASM teardown crash)#11
Merged
Merged
Conversation
The touch and segmenter worker pools called worker.terminate() without
awaiting it, so stop() (and the local server close path that calls it)
resolved while the worker threads were still tearing down.
When @prisma/streams-local runs in-process inside @prisma/dev, those lingering
worker threads outlive the server close and race the host process freeing
PGlite (WebAssembly) JIT pages. That trips V8 process-global JIT bookkeeping
(PKU/ThreadIsolation) and aborts the process on Linux:
# Check failed: jit_page_->allocations_.erase(addr) == 1
Make the pool stop() await every terminate(), and thread that await up through
TouchProcessorManager.stop, the app_core close, and the local server close so a
resolved close guarantees the worker threads are gone.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Will Madden <madden@prisma.io>
wmadden
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both worker pools tear down like this:
worker.terminate()returns a promise that isn't awaited, sostop()— and the local-serverclose()path that calls it — resolves while the worker threads are still tearing down.That's invisible for the standalone server (its own process), but
@prisma/streams-localalso runs in-process inside@prisma/dev. There,await localServer.close()returns while the touch/segmenter worker threads are still alive, and@prisma/devimmediately tears down PGlite (Postgres compiled to WebAssembly). A worker thread terminating at the same moment another thread frees PGlite's WASM JIT pages races V8's process-global JIT bookkeeping (PKU / ThreadIsolation) and aborts the whole process on Linux:Every operation succeeds; the process just dies during teardown. Downstream (prisma-next) it surfaced as a flaky vitest "Worker exited unexpectedly" with all tests passing — frequent in high-churn suites that create and close many dev servers in one process, rare in low-churn ones.
Fix
Await termination, and thread that await all the way up the close path so a resolved
close()guarantees the worker threads are gone:TouchProcessorWorkerPool.stop()/restart()→ async,await Promise.all(workers.map(w => w.terminate()))SegmenterWorkerPool.stop()→ sameTouchProcessorManager.stop()→ async, awaitspool.stop()(and the in-looppool.restart())app_coreclose()→ async, awaits the worker-pool stops before the restlocal/server.tsandserver.ts→await app.close()Notes
DurableStreamsLocalServer.close()was alreadyPromise<void>, so this is backward-compatible for callers that await it (@prisma/devdoes).tsc --noEmitclean;local_server,segmenter_behavior, andtouch_memory_journalsuites pass. The crash itself only reproduces on Linux with an in-process WASM host (PGlite), which this repo doesn't have, so there's no repro test here — the prisma-next e2e suite is the end-to-end guard once a new@prisma/streams-localis published.🤖 Generated with Claude Code