We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 143dfc7 commit 7bc2a0bCopy full SHA for 7bc2a0b
statemachine.go
@@ -309,10 +309,13 @@ func (sm *StateMachine) stateRepresentation(state State) *stateRepresentation {
309
sr, ok := sm.stateConfig[state]
310
sm.stateMutex.RUnlock()
311
if !ok {
312
- sr = newstateRepresentation(state)
313
sm.stateMutex.Lock()
314
- sm.stateConfig[state] = sr
315
- sm.stateMutex.Unlock()
+ defer sm.stateMutex.Unlock()
+ // Check again, since another goroutine may have added it while we were waiting for the lock.
+ if sr, ok = sm.stateConfig[state]; !ok {
316
+ sr = newstateRepresentation(state)
317
+ sm.stateConfig[state] = sr
318
+ }
319
}
320
return sr
321
0 commit comments