-
Notifications
You must be signed in to change notification settings - Fork 140
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
fix possible race condition in get_async_backend
, Fixes 425.
#714
fix possible race condition in get_async_backend
, Fixes 425.
#714
Conversation
My only concern with this is performance – this function is called a lot. I'd like to see some benchmarks against the previous version to ensure that there is no notable performance degradation. |
I ran a benchmark and was surprised by the performance drop. It was noticeable. So I made a new, more performant version - it is not as bulletproof as before, but it works and still fixes the problem. It may be insecure if a following occurs: In this case, But in the current version of the code, the |
Looks much better. Please add a changelog note (credit yourself and add the appropriate issue link) and I'll merge. |
i believe that there are ways to do this that will incur neither the problem you mention in the quote nor major performance degradation. e.g. i think a technique like in master...9d2d95c should be good on both of these fronts1. Footnotes
|
Can you elaborate on how this is different from what anyio does right now? |
@DavidJiricek would you mind adding a changelog entry? |
Just got hit by this race condition, thanks for the fix @DavidJiricek ! |
the the way that master...9d2d95c is different is: the cache it uses is not |
Yes, I can see that this is indeed a preferable solution. Why the |
Following the suggestion of @gschaffner, I think you should modify the solution to store the backend class in a dict on a successful |
yeah, agreed. I think my thought process was that weakrefs would let the module get GC'd if it's no longer in use and someone forcibly unloads it ( |
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.
a couple minor comments, at your discretion. otherwise LGTM!
Co-authored-by: Ganden Schaffner <[email protected]>
Thanks! |
Related issue is #425