Skip to content

fix: atomic entity file writes to avoid corruption on process kill - #5

Open
liamburja wants to merge 1 commit into
mainfrom
fix/atomic-entity-file-writes
Open

fix: atomic entity file writes to avoid corruption on process kill#5
liamburja wants to merge 1 commit into
mainfrom
fix/atomic-entity-file-writes

Conversation

@liamburja

Copy link
Copy Markdown

writeEntityRows wrote directly to .json. A process killed mid-write (e.g. Cloud Run SIGTERM/SIGKILL) could leave it truncated, and if the pending commit still reached the remote before the kill, the corrupted file would be permanently baked into git history and break every future clone.

Now writes go to a sibling temp file and rename() over the target, which is atomic on the same filesystem. A .gitignore for *.tmp is created on init so a leftover temp file (killed between write and rename) never gets committed.

writeEntityRows wrote directly to <entity>.json. A process killed mid-write
(e.g. Cloud Run SIGTERM/SIGKILL) could leave it truncated, and if the pending
commit still reached the remote before the kill, the corrupted file would be
permanently baked into git history and break every future clone.

Now writes go to a sibling temp file and rename() over the target, which is
atomic on the same filesystem. A .gitignore for *.tmp is created on init so a
leftover temp file (killed between write and rename) never gets committed.
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.

2 participants