test(session): add concurrent regression test for State.All()#725
Open
nuthalapativarun wants to merge 4 commits intogoogle:mainfrom
Open
test(session): add concurrent regression test for State.All()#725nuthalapativarun wants to merge 4 commits intogoogle:mainfrom
nuthalapativarun wants to merge 4 commits intogoogle:mainfrom
Conversation
state.All() previously released the read lock between each map iteration step, allowing concurrent Set() calls to trigger a fatal "concurrent map iteration and map write" panic (issue google#561). The fix (maps.Clone snapshot under lock) is already in place. This commit adds TestInMemoryState_All_ConcurrentSet to verify the fix holds under -race and prevent future regressions: it races State.All() against 8 concurrent goroutines each appending events with state deltas. Fixes google#561
Author
|
Hi, just checking in on this one — happy to make any adjustments if something needs to change. Let me know if there's anything blocking review. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue
Fixes #561
Description of Change
Problem:
state.All()previously released the read lock between each map iteration step (s.mu.RUnlock()inside therange s.stateloop), allowing concurrentSet()calls to mutate the map mid-iteration and trigger a fatal"concurrent map iteration and map write"panic.Solution:
The fix (snapshotting the map under lock via
maps.Clonebefore iterating) is already insession/inmemory.go. However, no concurrent test existed to verify this and guard against future regressions. This PR addsTestInMemoryState_All_ConcurrentSetwhich:State.All()(200 iterations) against 8 goroutines each appending events with state deltas concurrentlygo test -raceTesting Plan
Unit Tests:
TestInMemoryState_All_ConcurrentSetadded tosession/inmemory_test.goChecklist