Skip to content

fix(store): one O_APPEND write per append (closes #23) - #25

Merged
abogartz merged 2 commits into
mainfrom
fix/atomic-append
Oct 21, 2026
Merged

abogartz merged 2 commits into
mainfrom
fix/atomic-append

Conversation

@abogartz

Copy link
Copy Markdown
Owner

Closes #23. Regression test (store rows cannot be forged through content in test/logfmt.test.ts): 50 concurrent appendLog calls must all survive. On main the same storm leaves ~2 rows (review probe: 20 attempted → 2 survived); the new concurrent appends lose nothing test fails there and passes here.

One behavioral note baked into the comment: the fix deliberately uses node:fs/promises.appendFile rather than Bun.write(file, line, { append: true }) — measured on Bun 1.4.3, the Bun option silently truncates instead of appending (verified: "A" then append "B" leaves "B"). appendFile's a flag is O_APPEND|O_CREAT — atomic small writes on local POSIX filesystems, so the viewer process and the service can both append the same day file.

Full gate on this branch: 195 tests / 0 fail, tsc --noEmit clean.

…ger lose rows

appendLog was read-modify-write with an await between read and write:
20 concurrent appends to one file left 2 rows on disk (issue #23 probe).
node:fs/promises appendFile uses the 'a' flag (O_APPEND|O_CREAT), atomic
for small writes on local POSIX filesystems — covering both interleaved
async tasks in the service and the viewer as a second writer.

Note for the future: do NOT convert this back to Bun.write with an
options object — on Bun 1.4.3 the append option silently truncates.
@abogartz
abogartz merged commit 2361256 into main Oct 21, 2026
2 checks passed
@abogartz
abogartz deleted the fix/atomic-append branch October 22, 2026 00:58
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.

appendLog lost-update race: 20 concurrent appends -> 2 survived

1 participant