Skip to content

fix(fs-core): release removed inodes in rm and rmdir - #1302

Open
pawelzwronek wants to merge 1 commit into
streamich:masterfrom
pawelzwronek:fix/rm-inode-retention
Open

pawelzwronek wants to merge 1 commit into
streamich:masterfrom
pawelzwronek:fix/rm-inode-retention

Conversation

@pawelzwronek

Copy link
Copy Markdown

rm() and rmdir() remove directory entries but leave the removed nodes in Superblock.inodes, retaining their file buffers for the lifetime of the volume. Repeatedly creating and removing the same files therefore accumulates unreachable file data.

Release the removed subtree's inodes after detaching its directory entry. Skip . and .., decrement each removed file's link count, and retain nodes with hard links outside the subtree. Open files keep their existing Node and buffer through the descriptor table, so reads remain valid after removal.

Add 10 deterministic regression cases covering individual files, recursive rm/rmdir, empty directories, hard links inside and outside the subtree, open descriptors, symlinks inside a subtree, and inode-number reuse. All 10 fail before the fix and pass afterward. The tests inspect inode ownership rather than relying on GC timing or RSS.

Validation on Windows x64, Node v24.13.1, Yarn 4.12.0:

  • Build passes, including rebuilding fs-core after the source change.
  • yarn test: 101 suites passed; 1627 tests passed, 18 skipped; 14 snapshots passed.
  • yarn typecheck passes.
  • yarn prettier:check passes.
  • TSLint on the changed files reports one pre-existing no-duplicate-imports violation at Superblock.ts:8; the same violation occurs on the original HEAD file. The new test file has no TSLint violations. TSLint is not part of the current checks workflow.
  • A separate --expose-gc benchmark against the built checkout creates 256 files of 2 MiB per round. After three rounds for each of rm, recursive rm, and unlink, arrayBuffers returns to 2.04 MiB, with only the root inode and zero descriptors remaining. The benchmark retains a 2 MiB source buffer deliberately.

The change keeps existing path resolution, permission checks and volume-level deletion events. It does not attempt to fix separate symlink-resolution behavior in rm.

GPT-6.1 Sol ran all the tests and created the fix. I only spotted a memory leak after using rmSync() :P

This branch has not been deployed

No deployments
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