-
Notifications
You must be signed in to change notification settings - Fork 42
Avoid unnecessary env updates to reduce chances of segfault #956
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
Avoid unnecessary env updates to reduce chances of segfault #956
Conversation
See syrupy-project#955 for a detailed explanation of why this can cause thread safety issues resulting in a segfault when another thread calls `getenv`
If neither operand is a `SnapshotAssertion` then the rest of the code is not going to do anything, so bail early rather than unnecessarily setting up `__terminal_color` etc. which can cause issues c.f. syrupy-project#955
Codecov ReportAll modified and coverable lines are covered by tests ✅ @@ Coverage Diff @@
## main #956 +/- ##
==========================================
- Coverage 97.76% 97.71% -0.06%
==========================================
Files 21 21
Lines 1613 1616 +3
==========================================
+ Hits 1577 1579 +2
- Misses 36 37 +1 |
Happy to explore that as an option -- will add that to the v5 backlog |
@all-contributors add @sparrowt for bug fix |
I've put up a pull request to add @sparrowt! 🎉 |
🎉 This PR is included in version 4.8.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Thanks so much for the quick response & release as well - much appreciated! Looks like I can remove my monkey patch and use an official version after all which is always nicer 🎉 |
Description
This PR reduces unnecessary calls to
os.environ.update
(viaenv_context
) in order to reduce the probability of a segmentation fault caused by a race withgetenv
in another thread as described by #955Related Issues
os.environ
is modified (whenassert
compares 2SnapshotAssertion
instances and--snapshot-no-colors
is enabled) so I'm not sure this PR should be marked as one taht "fixes" that issuecontextvars
instead?Checklist
Additional Comments
Applying this patch locally allowed our playwright test run to complete 200 full runs with zero segfaults (whereas previously it was segfaulting roughly once on every 5-15 runs).