This repository was archived by the owner on Sep 1, 2022. It is now read-only.
Repository navigation
Fix for #396 LinkContext shutdown datarace - #435
Closed
neilstephens wants to merge 2 commits into
Closed
neilstephens wants to merge 2 commits into
neilstephens wants to merge 2 commits into
Conversation
The problem is that the link keepalive and response timers on LinkContext could have outstanding handlers at the time of shutdown. Most of the time this is OK, because the handlers get cancelled on OnLowerLayerDown() and usually execute with operation aborted error code. But in the case where a timer handler is already queued for execution when OnLowerLayerDown() is called, it executes with a success error code and goes on to access LinkContext members which are in the process of being destroyed. This fix copies a weak pointer to the ILinkSession into the handlers. The link session abstraction is the top level of the composition that the LinkContext is a part of, and hence lifetime is tied to. This way the handlers can check if their logical lifetime has ended and return instead of racing with the destruction of the LinkContext.
Contributor
Author
|
This PR replaces #395, which was just a proof-of-concept fix. This fix is a more elegant solution. I took the time to understand how the lifetime of the link layer is managed. I understand that the LinkContext is just a part of the LinkLayer composition, who's lifetime is already managed by a shared_ptr on the transport stack. The LinkContext already held a reference (raw pointer) to the LinkLayer base class ILinkSession, so I just moved enable_shared_from_this to the base class, and a capture a weak_ptr in the handlers to avoid the race. |
Member
|
Closing this in favour of #407. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The problem is that the link keepalive and response timers on LinkContext
could have outstanding handlers at the time of shutdown.
Most of the time this is OK, because the handlers get cancelled on OnLowerLayerDown()
and usually execute with operation aborted error code.
But in the case where a timer handler is already queued for execution
when OnLowerLayerDown() is called, it executes with a success error code
and goes on to access LinkContext members which are in the process of being destroyed.
This fix copies a weak pointer to the ILinkSession into the handlers.
The link session abstraction is the top level of the composition that
the LinkContext is a part of, and hence lifetime is tied to.
This way the handlers can check if their logical lifetime has ended and return
instead of racing with the destruction of the LinkContext.