Fix client self cancel#194
Merged
Merged
Conversation
It is not safe to allow the event callback function to be freed while it is executing. This is UB. Currently possible by cancellation, or the onEvent expert method. 1. onEvent() from a callback becomes logic_error 2. Explicit Subscription::cancel() during callback is made safe. Defer free to a later repeat cancel() or dtor. 3. Apply the same logic to onInit
Also privatize struct Discovery with added notify_busy flag.
Log an error when an operation created with syncCancel=true is allowed to be free'd asynchronously on the client worker. This may indicate that the Operation/Subscription is directly owned by its own callback. Creating a self-reference loop. Or it might indicate a more complicated, but safe, situation like pvalink where a new operation is initiated as the previous one completes. Use the syncCancel=false flag, opting of blocking cancellation, as an indication that this risk is accepted by user code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Attempt to resolve #192 . Alternative to slac-epics#18 , including a modified version of that added test case.
@george-mcintyre Please have a look.
The basic goal is to prevent Operation/Subscription callback functors from being free'd while executing. There are two situations where this may happen. With API calls which allow a new functor to be set, and as part of cancellation. This PR changes such that:
logic_error.cancel()during callback execution will silent skip freeing the functor. This being deferred to a later repeatedcancel(), or destruction.syncCancel==true(the default).With this new ERR condition. Such situations with
syncCancel==trueare assumed to be accidental, where the caller is not aware of the possibility of a self-reference loop. eg. The Operation owns the callback which owns the Operation which ... This is not always true though. As was the case in QSRV changed by this PR. However, I think that all such situations should anyway setsyncCancel==false.Mechanically, "busy" flags are added for all callback functors. This includes in the
Discoveryclass, which is also moved to be local todiscovery.cpp.Functor lifetime during the
handle_*()methods is tied to a shared_ptr, which remains in-scope until the end of the method. So, with the added "busy" flags repected, the functor can not be destructed during execution.