Harry Miller 7bd9e18500
fix(audit): use atomic write to prevent torn lines under concurrent O_APPEND (#3301)
The previous implementation used bufio.NewWriter which could split a
single entry into multiple write() syscalls. Under concurrent O_APPEND
from multiple goroutines, these partial writes interleave, producing
corrupted lines that the scanner silently drops.

Fix: encode into a bytes.Buffer first, then issue a single f.Write()
call. For payloads under PIPE_BUF (4096 bytes on Linux), this is
guaranteed atomic by POSIX.

Fixes flaky TestAppend_ConcurrentWritersUniqueIDs in CI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-17 15:10:26 -07:00
..