Skip to content

fix: compile the completion dump atomically - #396

Merged
jiminu merged 2 commits into
mainfrom
jiminu/zcompdump-lock
Oct 17, 2026
Merged

jiminu merged 2 commits into
mainfrom
jiminu/zcompdump-lock

Conversation

@jiminu

@jiminu jiminu commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • zcompile unlinks ~/.zcompdump.zwc and recreates it read-only (0444) in place. When several shells start together (e.g. a terminal restoring tabs after login), one shell's open(O_CREAT) hits the file another just created and prints can't write zwc file.
  • Compile into a private .zcompdump.tmp.<pid>.<random>.zwc and mv -f it over the shared .zwc, for both the audited rebuild and the stale-bytecode recompile. compdump already writes atomically.
  • zsh still loads the renamed bytecode: the entry is keyed by the source path, not the .zwc name.
  • Skip the compile when a directory occupies .zcompdump.zwc: mv -f would move the file into it instead of replacing it.

Tests

  • New TestNativeConcurrentDumpCompile: 8 concurrent zsh processes × 20 startups that each recompile; asserts no output and no leftover temp files. It fails 3/3 against the previous code and passes 5/5 with the fix.
  • The same test covers the directory case; removing the guard makes it fail.
  • bash scripts/check.sh locally: everything passed except TestNeovimDAPConfiguration, which also fails on unmodified main locally (passes in main CI); unrelated to this change.

zcompile unlinks the shared .zcompdump.zwc and recreates it read-only in
place, so shells starting together (a terminal restoring several tabs)
race and fail with "can't write zwc file". Compile into a private file
and rename it over the shared one.
mv -f moves the compiled file into a directory at the target instead of
replacing it, so a directory there would collect a file on every rebuild.
@jiminu
jiminu merged commit a09580b into main Oct 17, 2026
7 checks passed
@jiminu
jiminu deleted the jiminu/zcompdump-lock branch October 17, 2026 13:40
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