Repository navigation
fix: stop a failed request from hanging Python in Safari - #502
Merged
Merged
Conversation
Safari's fetch rejects with a TypeError that has no stack, which Pyodide 0.29.5 does not take for an error, so an await on a failed request never returned and the run hit its 120 s deadline. The data client now installs a guard on _pyodide._future_helper.set_exception before the seal. test-worker-core.js uses Bun's real refused-connection rejection (same shape as Safari's) in place of the JS-made stand-in that hid the hang; it fails without the guard. Refs #496
osa-bridge.js sends the runtime's guard, silently, to each new kernel before the setup cells, so a failed request in Safari raises in its cell instead of leaving the kernel busy. test-bridge.js checks the copy equals buildRejectionGuardSource() and that a refused pyfetch hangs without it and raises with it; e2e-check.js checks the guard reached the kernel (fails in Chrome with the bridge change reverted). Refs #496
…hang # Conflicts: # CHANGELOG.md
Post the notebook's 'none' setup status only after the guard is sent, as the path with setup cells already does. A rejection with no reason now says so rather than 'None'; test-bridge.js checks it (fails without the change). Runtime bundle rebuilt. Refs #496
3 tasks
Contributor
Preview Deployment
This preview will be updated automatically when you push new commits. |
This was referenced Sep 24, 2026
JavaScript null reaches the guard as Pyodide's jsnull and was reported as "jsnull"; it now reads "a promise was rejected with no reason", as undefined already did. Both copies of the guard change together, and the runtime bundle and the widget's integrity line are rebuilt. Tested: bun notebook/test-bridge.js and frontend/test-worker-core.js (null cases in the next commit fail without this change), runtime bundle --check, test-runtime-lifecycle.js, chrome.js. Refs #496
Both suites now check that a Python exception rejected through JavaScript keeps its type (a guard that wrapped everything fails here), that a stackless AbortError-shaped rejection raises as JsException: AbortError, and that null and undefined read as no reason. test-worker-core.js gains a canary that Bun's refused-connection rejection still has no stack, and reads through osa.fetch_bytes after the failure in the same session. test-bridge.js adds an unguarded control for the stackless shape. Tested: test-bridge.js 14/14, test-worker-core.js 197/197; mutating the guard to always wrap fails the type check in both, and dropping the jsnull case fails the null check in both. Refs #496
The bridge sends the guard as soon as the notebook's panel exists, before the document and theme waits, and no longer awaits its reply: JupyterLite 0.8.4 runs a kernel's requests in arrival order through one FIFO mutex, so being sent first is enough, and a reply can be lost when JupyterLite cancels requests queued behind a failed one. A probe sent at the first moment the kernel's connection existed ran after the guard in Chrome 153 and WebKit 26.6. The remaining window, a cell run while the kernel restarts, is documented at the call site. e2e-check.js now also checks the guard after a restart. Tested: notebook/e2e-check.js all checks pass in Chrome; with the restart path's guard removed, the new restart check fails (got null); test-bridge.js 14/14; WebKit nm000132 second cell raises in 0.5 s and the kernel keeps answering. Refs #496
neuromechanist
added a commit
that referenced
this pull request
Sep 25, 2026
Brings in #502, #503 and #508. The generated runtime bundle and its integrity line are rebuilt from the merged sources; CHANGELOG keeps both Added entries. Tested: bun scripts/build-runtime-bundle.js --check; test-worker-core (220), test-data-lane (106), test-runtime-bundle (25), test-widget-tools (397), test-runtime-lifecycle and test-egress all passed.
This was referenced Sep 25, 2026
Merged
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.
Refs #496. This does not close it: the issue closes after a check in Safari itself.
What was wrong
When a request fails, Safari's
fetchrejects with aTypeErrorwhose only own property ismessage. It has nostack.Pyodide 0.29.5 treats a JavaScript value as an error only if it has a
name, amessageand astack, or is aDOMException(JsProxy_compute_typeflags).Any other rejection reaches
_pyodide._future_helper.set_exceptionas a plain JsProxy. asyncio'sFuture.set_exceptionrefuses it, and the coroutine awaiting the request never resumes.In Safari, then, any request that fails hangs whatever awaits it:
[*]and the kernel stays busy.Chrome and Firefox are not affected, because their fetch errors carry a stack.
The change
buildRejectionGuardSource()infrontend/osa-egress.jswrapsset_exception. Anything asyncio would refuse becomes aJsExceptionwith the JavaScript name and message, and a JavaScriptundefinedornullreads "a promise was rejected with no reason". Everything else passes through untouched, including a Python exception, which keeps its type.notebook/osa-bridge.jssends the same Python, silently, to the kernel as soon as the notebook's panel exists, and again after a restart.This fixes only the hang. The notebook's own reads in Safari and Firefox still fail, now at once and with the URL, until the eegprep-lean change below is re-vendored.
Tests
frontend/test-worker-core.jsfails without the guard:OSError.AbortErrorraises as one.nullandundefinedread as "no reason".notebook/test-bridge.jschecks that the bridge's copy equals the runtime's, and that both stackless shapes hang without the guard (controls). It covers the same cases under the guard.notebook/e2e-check.jschecks the guard in Chrome after opening and after a restart. With the restart path's guard removed, it fails.set_exceptionalways wrap fails the type check in both suites, and dropping thejsnullcase fails the null check in both.--checkandchrome.jspass.Measured in WebKit 26.6 (Playwright 1.63, headless; not Safari)
[*]forever, kernel busyTransportError ... (index.json)in 0.5 s, kernel idle, next execution runstimeoutafter 120,001 ms, variables lostTransportErrorin 5 ms, variables keptNot fixed here
PyfetchTransportsendsUser-Agent. WebKit and Firefox send that header, which makes the request a CORS preflight, and zarr.nemar.org allows onlyRange. The fix is eegprep-lean: PyfetchTransport's User-Agent header fails every read in Safari and Firefox sccn/eegprep#419, then a re-vendor undersrc/assistants/nemar/runtime/, whose wheel the notebook site serves._pyodideis not blocked by the seal. That is a separate issue, Sealed code reaches the worker's global scope: block _pyodide, and cover storage and postMessage #506.