Fix bug with worker running after closing the page - #480
Open
cupicmarko wants to merge 1 commit into
Open
Conversation
Each page (index.html/admin.html) spawns its own dedicated storage worker, which installs an OPFS SQLite VFS (sahpool). Navigating between them raced the outgoing worker's OPFS handle release against the incoming worker's acquire, and the failure was consistently misreported: - OpfsSAHError's Display/Debug never interpolate the wrapped JsValue, so the lock-detection heuristic (is_opfs_locked_error) was matching against a string that could never contain the real DOMException text, always falling through to a generic "Failed to initialize" toast. - After fixing detection to inspect the DomException directly, a retry loop was added to tolerate the async release race — but pause_vfs() refuses to release handles while SQLite still has files open, and the worker never closed its connection, so the "release on pagehide" path was a silent no-op. Fixes, in order of effect: - is_opfs_locked_error now matches on OpfsSAHError::CreateSyncAccessHandle and checks the wrapped DomException's name directly. - storage worker retries sahpool::install for ~2s on a detected lock before surfacing the "another tab" message, tolerating the normal async handle-release delay. - New Pause request: on the page's `pagehide` event, the main thread fire-and-forgets a Pause call; the worker now drops its live SQLite connection first (closing the VFS file) so pause_vfs() can actually succeed, releasing the OPFS pool before the browser tears the worker down.
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.
Each page (index.html/admin.html) spawns its own dedicated storage worker, which installs an OPFS SQLite VFS (sahpool). Navigating between them raced the outgoing worker's OPFS handle release against the incoming worker's acquire, and the failure was consistently misreported:
Fixes, in order of effect:
pagehideevent, the main thread fire-and-forgets a Pause call; the worker now drops its live SQLite connection first (closing the VFS file) so pause_vfs() can actually succeed, releasing the OPFS pool before the browser tears the worker down.Note: The issue is reproduced in Firefox