CRITICAL: Data race in State.Save() — mutates snapshot under RLock #17
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/dnswatcher#17
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug
State.Save()ininternal/state/state.goacquiress.mu.RLock()but then mutates the snapshot:RLockallows concurrent readers, but this is a write operation. IfSave()runs concurrently withGetSnapshot()or anotherSave(), this is a data race.Impact
Race condition that can cause corrupted
LastUpdatedtimestamps or panic under the race detector. In practice,Save()is called from the watcher goroutine andGetSnapshot()could be called from HTTP handlers concurrently.Fix
Either:
Save()to uses.mu.Lock()(full write lock), orLastUpdatedbefore acquiring the lock and pass it in, keepingRLockfor the marshal+write portion.