Data race on state.State between mailbox goroutines ai:claude-sonnet-5-5 #46

Open
opened 2026-10-24 09:13:08 +02:00 by heiko · 0 comments
Owner

Found by a 100 Go Mistakes review (#58 race problems, #69). Verified by reading the code; not reproduced (no existing test runs more than one mailbox).

Where: internal/app/app.go:612-660 (Run), scanDelta, RunMailbox; internal/state/state.go:60 (States.Save).

Problem: each mailbox goroutine mutates its own *state.State (LastUID, HighestModSeq, ...) without a lock. saveStates holds saveMu, but States.Save marshals the whole map, including other mailboxes' structs that are being written concurrently. With two or more mailboxes this is a data race (go test -race with a multi-mailbox test should flag it) and can persist torn values.

Fix: guard each State with its own mutex, or perform state updates inside saveStates under saveMu. Add a multi-mailbox test run under -race.

(co)authored by ai:claude-sonnet-5-5

Found by a 100 Go Mistakes review (#58 race problems, #69). Verified by reading the code; not reproduced (no existing test runs more than one mailbox). **Where:** `internal/app/app.go:612-660` (`Run`), `scanDelta`, `RunMailbox`; `internal/state/state.go:60` (`States.Save`). **Problem:** each mailbox goroutine mutates its own `*state.State` (`LastUID`, `HighestModSeq`, ...) without a lock. `saveStates` holds `saveMu`, but `States.Save` marshals the *whole* map, including other mailboxes' structs that are being written concurrently. With two or more mailboxes this is a data race (`go test -race` with a multi-mailbox test should flag it) and can persist torn values. **Fix:** guard each `State` with its own mutex, or perform state updates inside `saveStates` under `saveMu`. Add a multi-mailbox test run under `-race`. (co)authored by ai:claude-sonnet-5-5
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
IUS/xr-invoiced#46
No description provided.