Skip to content

vfs: preserve open unlinked SharedFS files#786

Draft
brandonpayton wants to merge 1 commit into
mainfrom
gascity/kd-c5i.11-sharedfs-open-temp-lifetime
Draft

vfs: preserve open unlinked SharedFS files#786
brandonpayton wants to merge 1 commit into
mainfrom
gascity/kd-c5i.11-sharedfs-open-temp-lifetime

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

Summary

Fixes the SharedFS file-lifetime bug behind the SQLite sort2 temp-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 later pread on 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/writeAt operations to SharedFS, and routes MemoryFileSystem pread/pwrite through 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.ts pthread/fork cases, test/pthread-trap-semantics.test.ts, test/pthread.test.ts, and test/wasm64.test.ts missing programs/wasm64/hello64.wasm\n - the new test/vfs/sharedfs-positioned-io.test.ts passed in this full run\n\nPreviously recorded on bead kd-c5i.11 before 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 from origin/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.

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.
@github-actions

Copy link
Copy Markdown

Phase B-1 matrix build status — pr-786-staging

ABI v16. 6 built, 0 failed, 6 total.

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.

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.

1 participant