fix(ipcutil): make Write thread-safe with internal mutex (PILOT-287)#11
fix(ipcutil): make Write thread-safe with internal mutex (PILOT-287)#11matthew-pilot wants to merge 1 commit into
Conversation
ipcutil.Write did two sequential w.Write calls (4-byte length header + payload) with no internal synchronisation. Concurrent callers sharing the same io.Writer could interleave the length header of one message with the payload of another, producing wire-format corruption. Add a package-level sync.Mutex (writeMu) so the header+payload pair is written as an atomic unit. The daemon already serialises writes through a single writeLoop goroutine per connection, so the mutex adds zero additional contention in practice. Also add TestWriteConcurrent: 200 goroutines write distinct payloads into the same backing buffer; after all writes complete, 200 valid messages are read back and verified to be unique and intact. Closes PILOT-287
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Matthew PR Status — #11Title: fix(ipcutil): make Write thread-safe with internal mutex (PILOT-287) TicketsLabels
CI Checks2/2 passing (0 failing)
Files Changed
Next Actions
Auto-generated status check by matthew-pr-worker |
Matthew PR Explain — #11What this PR doesfix(ipcutil): make Write thread-safe with internal mutex (PILOT-287) Scope
TicketsFiles
Review Notes
Auto-generated explain by matthew-pr-worker |
🤖 Matthew Pilot — CI Status
Verdict: All checks green. Ready for review. |
🤖 Matthew Pilot — PR SummaryPILOT-287 — Makes What changedAdded a package-level Root cause
Changes
ImpactIn practice, the daemon already serialises writes through a single goroutine per connection, so the mutex adds zero contention in the hot path. Verdict✅ Builds, vets, and tests pass. 2 files, +62 lines. 200-goroutine concurrent test. |
What
ipcutil.Writedid two sequentialw.Writecalls (4-byte length header + payload) with no internal synchronisation. Concurrent callers sharing the sameio.Writercould interleave the length header of one message with the payload of another, producing wire-format corruption.Fix
Add a package-level
sync.Mutex(writeMu) so the header+payload pair is written as an atomic unit.ipcutil/ipcutil.go— +9 lines: added mutex + concurrency-safety doc commentipcutil/zz_test.go— +53 lines:TestWriteConcurrent— 200 goroutines write distinct payloads into the same backing buffer; after all writes complete, 200 valid messages are read back and verified unique + intactThe daemon already serialises writes through a single
writeLoopgoroutine per connection, so the mutex adds zero additional contention in practice.Verification
Diff stat
Closes PILOT-287