-
Notifications
You must be signed in to change notification settings - Fork 143
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
Bug Fix: Defensively copy context entities #340
Conversation
4f9b78d
to
d070b98
Compare
Thanks @tyler-dodge! Just curious, do you have a screenshot of this failing or the bug you observed? I think this change makes sense but I think it would be useful to see it breaking. (Or maybe unit tests that show it works if that’s easier to add?). |
Before this change, concurrent async tasks would all share the same instance of the entities list. This change makes it so they each get their own copy of the list. This matters because the recorder modifies the list in place, which makes it so concurrent subtasks have the wrong parent subsegment.
I added a unit test for it in the latest force push that I also verified failed prior to this change. |
Co-authored-by: Nathaniel Ruiz Nowell <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for your help Tyler! This is a great bug fix and I look forward to seeing it being deployed 🙂
I added some suggestions for documentation to help us in the future, would you mind taking a look? Thanks!
The modifications you added all look great to me. |
Description
Before this change, concurrent async tasks would all share the same instance of the entities list. This change makes it so they each get their own copy of the list.
This matters because the recorder modifies the
entities
list in place, which makes it so concurrent subtasks end up looking at the wrong item in theentites
list when deciding the parent subsegment:aws-xray-sdk-python/aws_xray_sdk/core/context.py
Lines 90 to 101 in 0f13101
You can see this in the unit test added. Before this change the unit test would print out the following:
With this change, all the subsegments have the correct parent ID.
(enowell) You can also visualize this in X-Ray from my tests:
Before:
Subsegments are children of each other even though they are concurrent:
After:
Subsegments have the correct parent ID.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
I think this possibly fixes the issue here:Fixes: #310
Fixes: #164