Repository navigation
Fix hangs in off-thread WebAssembly compilation - #522
Draft
wesgarland wants to merge 1 commit into
Draft
wesgarland wants to merge 1 commit into
wesgarland wants to merge 1 commit into
Conversation
- dispatchToEventLoop no longer takes the GIL. SpiderMonkey calls it on a helper thread holding the helper-thread lock; the JS thread, holding the GIL, can be waiting for that lock (starting another WebAssembly.compile), so the two deadlocked. It now starts a thread, without the GIL, that takes the GIL and enqueues the job; with no event-loop running it hands the task back to SpiderMonkey. - Off-thread tasks count as pending jobs (asyncTaskStarted/Finished callbacks), so pm.wait() waits for them. It returned while a compile ran; the promise never settled and the process hung in JS_DestroyContext at exit.
This branch has not been deployed
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.
Pythonmonkey can hang in off-thread WASM compilation. This can happen running dcp-client because of the makeSignature() code in the wallet API.
dispatchToEventLooptook the GIL on the SpiderMonkey helper thread, which holds the helper-thread lock; the JS thread, holding the GIL, waits for that lock inOffThreadPromiseTask::initwhen it starts another compile. It now starts a thread without the GIL, which takes the GIL and enqueues the job (or hands the task back withReleaseFailedTaskwhen no event-loop is running).pm.wait()returns while a compile runs. Nothing counted the in-flight task, so the event-loop finished, the promise never settled, and the process hung inJS_DestroyContextat exit. TheasyncTaskStarted/asyncTaskFinishedcallbacks now count off-thread tasks as pending jobs.Diagnosed on 1.5.1 (same
srcasmain) withpy-spy dump --native: the main thread inOffThreadPromiseTask::initand a helper thread inJobQueue::dispatchToEventLoopwaiting for the GIL; and the main thread injs::DestroyContextwaiting for the helper-thread lock.New tests
tests/js/wasm-compile-alone.simpleandwasm-compile-concurrent.simpleboth hang (timeout) on 1.5.1. Not built locally (no SpiderMonkey build here); CI is the first build.Behaviour change: a pending
Atomics.waitAsyncwith no timeout now also keepspm.wait()waiting.