-
Notifications
You must be signed in to change notification settings - Fork 37
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
Possible race condition when stopping a resource #277
Comments
I see now that the E_RESTART FB is handling the Start/Stop state changes in close relationship with the ecet, which would also require some re-thinking |
After some thought, my doubts are:
|
The description of the E_RESTART block is a bit vague in the standard. For years we have tried to come up with different interpretations how to correctly implement it. Your assessment helps that we can come to a better solution. This will also be important for the thing @MandKastner is currently to start working at. What I can do is to tell my understanding of E_RESTART: For me it is a means that allows to inform FB Networks in this resource that the execution of this resource has started or is stopped. The events it sends out shall be used to trigger any initialization initialization. Therefore I think that E_RESTART instances should be started and stopped separately to the FBs so that the triggered FBs can be informed and execute. For starting this is less critical as any output events that an E_RESTART block is sending are put into the ECET. So it is fine to first START all blocks and then the ECET. For STOPPING I think we need to first STOP E_RESTART, wait till all execution because of the STOP events completes. Stop ECET and then STOP all the FBS. Or did I miss anything. |
I see. I agree with the stopping procedure, but now I have more thoughts :)
|
One case when the problem occurs is when starting a resource and stopping it right afterwards, because some events are still running when the FB are changed to a
stopped
stated.The case I encountered was specifically in the BaseCommFB, where the INIT event was being executed and therefore the connection is being opened, and then the
changeExecutionState(stop/kill)
call arrives from another thread (usually the main thread) which closes the closes the connection deleteing the topComStack and causing issues.I think the problem is in the
CResource::changeExecutionState
where themResourceEventExecution
is stopped only after all the internal FBs are stopped. I believe we should change the states of the internal of the FBs only when we are sure that themResourceEventExecution
is not running anymore, meaning that the it should be stopped first, theecet
itself should first join its thread before returning and only then the FBs should be stopped.So, since the resource is a composition of a
ecet
and internal FBs, the order of the start of it should be:and the order of the stop of it should be the opposite:
stopping (and probably starting too) the ecet need to be synchronous to actually make sure that the ecet is in the desired state before continuing, otherwise you end up with a transit state where you triggered the change of the state, but it was not reached yet.
The text was updated successfully, but these errors were encountered: