fix: workaround for Task unwinding race condition#44
Closed
KowalskiThomas wants to merge 4 commits intokowalski/fix-on-cpu-tasksfrom
Closed
fix: workaround for Task unwinding race condition#44KowalskiThomas wants to merge 4 commits intokowalski/fix-on-cpu-tasksfrom
KowalskiThomas wants to merge 4 commits intokowalski/fix-on-cpu-tasksfrom
Conversation
…created Tasks fix: do not remove links for just-created Tasks
1d4b884 to
6a3631e
Compare
6e518ea to
d9a621d
Compare
fix: correctly unwind on-CPU tasks
d9a621d to
fc85934
Compare
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.
What does this PR do?
https://datadoghq.atlassian.net/browse/PROF-13137
In short
This depends on
Note that this PR (unfortunately) doesn't make all our problems go away (as the red CI testifies...)
There still are issues, just the one that I explained here is gone, as far as I can tell.
In depth
The PR aims at reducing the issues caused by race conditions between sampling of CPU Stacks and asyncio Stacks.
There are three places we can have a race condition. The race condition can happen because the three following events can happen at the same time as the Python thread that runs asyncio Tasks is living its life at the same time we are sampling:
Handle._run) (coroutine(s)) (sync functions called by coroutines)Runner._select)TaskInfo/GenInfoobjectsGenInfo's will have is_running set to trueTaskInfo::unwindwill show the “upper Python Stack” (sync entry point and asyncio runtime) on top of the Task’s Coroutine FrameIf any two of those three Samples are out of sync (one returns “we’re running this Task” and any other one returns “we’re not running this Task”), we are at risk of producing incorrect (and potentially inconsistent) Stacks.
GenInfoobjects are marked as off-CPU” (this leads to having one Frame of the previously-running Task in an unrelated Task’s Stack)GenInfoobjects are marked as on-CPU” and then “callingFrame::readdoesn’t detect the upper Stack” (this leads to having asynchronous Stacks that do not have their Python entrypoint/asyncio runtime Stacks attached on top)We need a way to either exclude those cases (give up on sampling) or recover from them (I think this will come at a performance cost). In this PR, I implemented the former, which is much easier to do and has no performance cost. We may lose a few samples as a result, but in practice this really rarely happens except upon Task completion.