vfs: preserve open unlinked SharedFS files#786
Draft
brandonpayton wants to merge 1 commit into
Draft
Conversation
SQLite sort2 uses temporary etilqs files by opening, unlinking, and continuing positioned I/O through the still-open fd. SharedFS removed and freed the inode at unlink time, so a later temp file could reuse the same inode while the original fd still existed. A subsequent pread on the old fd could then see EOF or replacement contents instead of the data previously written through that fd. Keep unlinked or rename-replaced inodes alive until the last fd closes, and add direct readAt/writeAt operations so MemoryFileSystem pread/pwrite no longer emulate positioned I/O by mutating the shared fd offset. Cover the fd-offset, unlink lifetime, rename-over lifetime, and MemoryFileSystem positioned-I/O cases with focused Vitest regression coverage. Validation on clean branch gascity/kd-c5i.11-sharedfs-open-temp-lifetime: bash scripts/dev-shell.sh bash -lc 'cd host && npx vitest run test/vfs/sharedfs-positioned-io.test.ts' passed 1 file / 4 tests; bash scripts/dev-shell.sh bash scripts/check-abi-version.sh passed. Full host Vitest was run and remains red from 9 failures in fork/pthread/wasm64 areas outside this SharedFS-only diff; the new SharedFS test passed in that run.
Phase B-1 matrix build status —
|
| Package | Arch | Status | Sha |
|---|---|---|---|
| kandelo-sdk | wasm32 | built | d5b38af6 |
| rootfs | wasm32 | built | a4db6ad3 |
| shell | wasm32 | built | 95517855 |
| lamp | wasm32 | built | bfeb3682 |
| node-vfs | wasm32 | built | b38d0c40 |
| wordpress | wasm32 | built | 0da1d75e |
Auto-generated; replaced on each push. Raw data in the publish-status workflow artifact.
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.
Summary
Fixes the SharedFS file-lifetime bug behind the SQLite
sort2temp-file failure: SQLite opens/tmp/etilqs_*, unlinks it, and continues positioned I/O through the open fd. SharedFS previously removed and freed the inode at unlink time, so a later temp file could reuse/reset that inode while the original fd still existed. A laterpreadon the old fd could then see EOF or replacement contents instead of the bytes previously written through that fd.This PR keeps unlinked or rename-replaced inodes alive until the last fd closes, adds direct
readAt/writeAtoperations to SharedFS, and routes MemoryFileSystempread/pwritethrough those operations instead of mutating the shared fd offset.Validation
Passed:
bash scripts/dev-shell.sh bash -lc 'cd host && npx vitest run test/vfs/sharedfs-positioned-io.test.ts'\n - 1 file passed, 4 tests passed\n-bash scripts/dev-shell.sh bash scripts/check-abi-version.sh\n - ABI snapshot/header/TS bindings up to date\n\nRun but red from unrelated/baseline areas on this clean SharedFS-only branch:\n\n-bash scripts/dev-shell.sh bash -lc 'cd host && npx vitest run'\n - 91 files passed, 25 skipped, 5 failed\n - 755 tests passed, 111 skipped, 2 expected fail, 9 failed\n - failing areas:test/fork-from-thread.test.ts,test/fork-instrument-coverage.test.tspthread/fork cases,test/pthread-trap-semantics.test.ts,test/pthread.test.ts, andtest/wasm64.test.tsmissingprograms/wasm64/hello64.wasm\n - the newtest/vfs/sharedfs-positioned-io.test.tspassed in this full run\n\nPreviously recorded on beadkd-c5i.11before creating this clean PR branch:\n\n- official browser^memsubsys1 sort2.test$passed 1/1 host job, 11 SQLite cases, 0 errors on the validated stacked worktree\n- official Node^memsubsys1 sort2.test$passed 1/1 host job, 11 SQLite cases, 0 errors on the validated stacked worktree\n\n## Notes\n\nThis draft PR intentionally contains only the SharedFS root-cause fix, not the earlier stacked SQLite/pthread work fromorigin/gascity/kd-cfo/kd-c5i.11-diagnose-official-memsubsys1-sort2-browser-timeout.\n\nNo ABI change is expected or observed. No user-facing docs update is included because this is a VFS correctness repair for existing POSIX open-unlink semantics, covered by focused runtime tests.