Skip to content

fix: drain eviction after-hooks with noDisposeOnSet - #430

Open
ychampion wants to merge 1 commit into
isaacs:mainfrom
ychampion:fix/drain-eviction-disposal
Open

ychampion wants to merge 1 commit into
isaacs:mainfrom
ychampion:fix/drain-eviction-disposal

Conversation

@ychampion

Copy link
Copy Markdown

With noDisposeOnSet enabled, set() leaves queued eviction disposeAfter callbacks undrained. The evicted key is gone, but its cleanup may wait until another operation flushes the queue. A cache using the hook to close file descriptors can therefore retain evicted resources.

Drain the queue after the cache update. Replacement suppression is already applied when disposal tasks are queued, so replacements remain suppressed while evictions clean up before set() returns.

Refs #427, finding 1. Other findings remain separate.

Validation:

  • The new regression fails 15 of 71 assertions on unchanged source. It covers count/size eviction, size-growth eviction, per-call/default suppression, explicit overrides, callback timing, replacement suppression and exactly-once cleanup.
  • Node 24.22.3: npm test -- -c -t0 --reporter=tap passes all 30 files; tap report text reports 100% statements, branches, functions and lines. Oxlint, Prettier and diff checks pass.
  • Fresh packed CommonJS/ESM consumers exercise 12 cases with 36 native file descriptors. The base retains evicted descriptors until later cleanup; the fix closes them immediately while preserving suppressed replacements. All descriptors are accounted for and closed.

Assisted by AI.

Signed-off-by: ychampion <68075205+ychampion@users.noreply.github.com>

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