8000 Avoid unnecessary env updates to reduce chances of segfault by sparrowt · Pull Request #956 · syrupy-project/syrupy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 3 commits into from
Feb 20, 2025

Conversation

sparrowt
Copy link
Contributor
@sparrowt sparrowt commented Feb 20, 2025

Description

This PR reduces unnecessary calls to os.environ.update (via env_context) in order to reduce the probability of a segmentation fault caused by a race with getenv in another thread as described by #955

Related Issues

Checklist

  • This PR has sufficient documentation -- I think so; it is a bugfix with sufficient explanation in the commit messages
  • This PR has sufficient test coverage -- not yet, I can add this if desired though it will be quite contrived I think
  • This PR title satisfies semantic convention.

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).

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
Copy link
codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Impacted file tree graph

@@            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     

@noahnu
Copy link
Collaborator
noahnu commented Feb 20, 2025

a more full solution may be to avoid setting the env at all if it's possible to replace this with use of contextvars instead?

Happy to explore that as an option -- will add that to the v5 backlog

@noahnu noahnu merged commit 7fdffd9 into syrupy-project:main Feb 20, 2025
15 of 17 checks passed
@noahnu
Copy link
Collaborator
noahnu commented Feb 20, 2025

@all-contributors add @sparrowt for bug fix

Copy link
Contributor

@noahnu

I've put up a pull request to add @sparrowt! 🎉

@noahnu
Copy link
Collaborator
noahnu commented Feb 20, 2025

🎉 This PR is included in version 4.8.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sparrowt
Copy link
Contributor Author

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 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0