qmuntal / stateless

Go library for creating finite state machines
BSD 2-Clause "Simplified" License
898 stars 47 forks source link

Concurrent issue on String() function #61

Closed youngSSS closed 11 months ago

youngSSS commented 11 months ago

When calling String() concurrently, it goes to panic. Is it possible to use sync.Map to avoid panic?

func (sm *StateMachine) stateRepresentation(state State) (sr *stateRepresentation) {
    var ok bool
    if sr, ok = sm.stateConfig[state]; !ok {
        sr = newstateRepresentation(state)
        sm.stateConfig[state] = sr // concurrent panic point
    }
    return
}
qmuntal commented 11 months ago

Thanks for reporting, will fix soon.