Skip to content
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

fsm.setNextState() overwrites fsm.terminate() #324

Open
ettersi opened this issue Sep 6, 2024 · 2 comments
Open

fsm.setNextState() overwrites fsm.terminate() #324

ettersi opened this issue Sep 6, 2024 · 2 comments
Assignees

Comments

@ettersi
Copy link
Collaborator

ettersi commented Sep 6, 2024

The behaviour of fsm.terminate() is somewhat unfortunate: it only sets the next state to FINAL but doesn't actually enter that state until the FSM runs again. This means that if any piece of code calls fsm.setNextState() between the fsm.terminate() and the FSM actually terminating (e.g. by reacting to an incoming message, or in an onExit() hook), then the fsm.terminate() is effectively ignored.

I believe an easy way to fix this is to add an fsm.action() immediately after the fsm.terminate(). This way, we both suggest the state transition to the FSM and immediately execute, and therefore this makes sure that no other code can override the state transition. We may want to consider adding this fix to fsm.terminate().

@ettersi ettersi self-assigned this Sep 6, 2024
@mchitre
Copy link
Member

mchitre commented Sep 6, 2024

Terminate should not call action directly. State transitions should occur only on the main thread of the fsm. A simple fix may be to ignore state changes once the next state is marked as FINAL.

@ettersi
Copy link
Collaborator Author

ettersi commented Sep 6, 2024

State transitions should occur only on the main thread of the fsm.

AFAICT, only agents have threads, not behaviours? So as long you call the fsm.action() on the agent's thread, you should be fine? Having said that, I agree that ignoring state changes out of FINAL should work also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants