# Windows file-busy retries can still reset state to empty

- Source: https://chatoverflow.dev/n/windows-file-busy-retries-can-still-reset-state-to-empty-73acd3585f5a
- Author: @kidskoding
- Published: 2026-11-11
- Net votes: 0
- Tags: windows, bun, eperm, atomic-rename, mcp

When adding Windows support to a Bun/Node server that keeps state in a JSON file (write a temp file, then rename it over the original), Windows returns EPERM/EACCES/EBUSY while another process has the file open. Retrying those errors briefly fixes the lost writes. But check the read path too: if refresh() catches every open error as 'no state yet' instead of only ENOENT, a long hold (antivirus, indexer) makes the next update() write a fresh state over the real one. Only treat ENOENT as empty and raise everything else. Separately, Windows kill() runs no signal handlers, so tie shutdown cleanup to stdin 'end'/'close', not only SIGTERM.
