-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transition Race Condition #6
Comments
If we take a step back and thing what is happening here, the story as I understand it is as follows:
The fact that these are running in goroutines does not make this a concurrent transition. There is only a single machine and it cannot be transitioned into an invalid state at any time. The second goroutine should have its expectations as: st.Expect(t, err, fsm.InvalidTransition)
st.Expect(t, thing.State, fsm.State("started")) Additionally, I was able to eliminate the strange behavior of having a valid transition seemingly return an error. The issue is with declaring the But, by removing the Finally, I'm not really sure what you're actually trying to test here. From what I can tell, it seems that the race condition is actually in the test itself and not the state machine. Maybe if I understood more of what scenario you're trying to address, we can come up with a test case that accurately represents it. EDIT: I've thought about it some more. I think a better test would involve two wait groups. We have an issue here in that we can't really predict when both goroutines will start. If we have each one wait until both goroutines signal they are running, and only start after that signal, we'll be able to see how the FSM really behaves. |
Ugh. I'm sorry about the So I was looking at this block of code, and I was wondering if it's possible for two goroutines have the if statement evaluate to true, thus updating state twice: If the consumer doesn't confirm state at the end, they could be running with the wrong assumption. |
I was just reviewing that exact same function. I think there is a possible issue there. There is a chance that two or more goroutines could run the It is undefined which one would be permitted in that scenario. I'm on the fence if it's better to simply document the possible issue here and leave it as an exercise to the consumer or to add a mutex on the |
Hey there,
I was taking a look at how your library was written and noticed that your transitions were not serialized using a mutex. I figured this would mean that your library would fail in cases where it shouldn't.
When I managed to reproduce it in testing, the failure was a bit more explosive than I thought it would be. When I wrote the test, I expected one of the goroutines would either: A) Fail with an
InvalidTransition
, B) Fail with the state being unexpected. However, both goroutines reported anInvalidTransition
error, while only one reported that the state was incorrect. At first-pass, I can't explain why both goroutines ended up getting anInvalidTransition
error. It would seem to confirm the race condition.Here is the diff and then the test output. The output shows two errors getting returned from Transition, when really one should do it.
Output:
The text was updated successfully, but these errors were encountered: