Skip to content

OPFSCoopSyncVFS: tolerate a temporary directory whose files are still open - #386

Merged
rhashimoto merged 1 commit into
rhashimoto:masterfrom
lalexdotcom:opfscoopsync-sweep-held-directory
Nov 15, 2026
Merged

rhashimoto merged 1 commit into
rhashimoto:masterfrom
lalexdotcom:opfscoopsync-sweep-held-directory

Conversation

@lalexdotcom

Copy link
Copy Markdown
Contributor

This is the PR offered in #362: NoModificationAllowedError added to the errors the sweep tolerates, with a test.

What happens

When OPFSCoopSyncVFS initializes, it deletes every .ahp-* directory whose lock it can get. A worker that goes away without closing its access handles can have that lock released before its handles are closed. A page evicted by the back/forward cache is one example (#362). The next instance then gets the lock, removeEntry() throws NoModificationAllowedError, and create() fails. Only NotFoundError is tolerated there today (#347).

It reproduces in Chrome and Firefox.

The change

The sweep also tolerates NoModificationAllowedError and leaves the directory in place. A later instance deletes it once its files are closed, the same way the sweep already handles a directory another instance deleted first. The change is one condition, and it costs nothing on the normal path.

The test

test/vfs_handover.js gets a case next to #347's. A worker holds an access handle on a file inside an .ahp-* directory, and nobody holds that directory's lock. A new instance must start. After the handle is closed, the instance after that one must delete the directory. On master the start fails with NoModificationAllowedError in Chrome and Firefox, for all three builds. With the change it passes. createHolder() in test/vfs_handle_recovery.js can now put the file in a subdirectory.

Fixes #362.

Conflict with #381

#381 also changes src/examples/OPFSCoopSyncVFS.js and test/vfs_handover.js. The source changes don't overlap and merge cleanly. The test file conflicts: both PRs add a case at the end of the same describe, and #381 changes startInstance() to resolve to { worker, port } instead of the worker.

This PR doesn't conflict with my other open PRs (#382, #384, #385).

Checklist

  • I grant to recipients of this Project distribution a perpetual,
    non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
    derivative works of, publicly display, sublicense, and distribute this
    Contribution and such derivative works.
  • I certify that I am legally entitled to grant this license, and that this
    Contribution contains no content requiring a license from any third party.

… open

A worker that goes away without closing its access handles, such as one
whose page the back/forward cache evicts, can have its directory's lock
released before its handles are closed. The next instance's sweep then
gets the lock, removeEntry throws NoModificationAllowedError, and
create() fails. The directory is left for a later instance to delete,
as it already is when another instance deleted it first (rhashimoto#347).

Fixes rhashimoto#362.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lalexdotcom

Copy link
Copy Markdown
Contributor Author

Rebased on master after #381: both cases kept in test/vfs_handover.js, with this one's startInstance() calls reading .worker.

@lalexdotcom
lalexdotcom force-pushed the opfscoopsync-sweep-held-directory branch from a21e9d4 to c4f832e Compare October 23, 2026 17:56
@rhashimoto
rhashimoto merged commit 90b356f into rhashimoto:master Nov 15, 2026
1 check passed
@rhashimoto

rhashimoto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Thanks for the PR! LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPFSCoopSyncVFS.create() fails with NoModificationAllowedError after a back/forward-cache navigation

2 participants