-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Close the socket if there's a failure in start_connection() #10464
base: master
Are you sure you want to change the base?
Conversation
It looks like the fix for this in uvloop has stalled out |
This comment was marked as outdated.
This comment was marked as outdated.
Looks like there is a test that will need to be adjusted as well |
Might also be the same issue reported here MagicStack/uvloop#631 |
The original aiohappyeyeballs issue is 5mo old |
I'm really starting to get the feeling uvloop isn't going go to fix this issue anytime soon as there are multiple comments saying they will look at it shortly but it doesn't happen. That's a bit frustrating but it's up to them how they want to prioritize. Edit: it looks like similar issue MagicStack/uvloop#631 has been sitting for nearly 6 months as well |
It looks like one of the connector tests is failing with this change. |
Oh, thanks a lot for all the context... Yeah this sounds good, I'll circle back to look at the test and add a comment and generally polish this up tomorrow. |
It looks like they are just not around at the moment, there appears to be no activity at all since just after that PR was opened. When they get back to the project, it'll probably be the first thing they do... |
Noticed the argument about whether it's worth it to maintain this complexity or not, polished up the PR anyway (fixed tests, added new test, added changelog) just so that it's actually ready if we do want it.
Yeah that makes sense. A counterargument here is that this generally hardens aiohttp by making it robust against event loop implementations. Also, even with a correct event loop implementation this would enable the socket destruction to potentially be hastened in this case where we know it's garbage. In any case this PR would unblock our |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #10464 +/- ##
==========================================
- Coverage 98.70% 98.69% -0.01%
==========================================
Files 122 122
Lines 37180 37203 +23
Branches 2058 2056 -2
==========================================
+ Hits 36698 36718 +20
- Misses 335 338 +3
Partials 147 147
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I'm fine with this change given explicitly closing the socket is still a good practice. |
I'd like to get a 👍 or at a comment from @Dreamsorcerer that he doesn't wan to hold this PR before merging. |
I've made one last attempt to ping the uvloop maintainers. If there's no response in a couple of days, then I guess we should merge this. |
What do these changes do?
Over in MagicStack/uvloop#653 in issue is described where after upgrading from aiohttp 3.9.5 -> 3.10.5 (but same thing on 3.11.11), under certain conditions where exceptions are raised at the right/wrong time, continued use of
aiohttp
can result inFile descriptor 2877 is used by transport
errors.I've been able to repro with a small script (gist) that starts/stops/cancels many connections repeatedly. I can repro on at least Ubuntu 24 x86, aiohttp 3.11.11 and uvloop 0.21.0. This fix resolves the errors in my repro script.
I was unable to produce a detailed end-to-end explanation for what's happening here, but I do know that we enter the error state when an exception is thrown while inside of uvloop's
create_connection
function, here:https://github.com/MagicStack/uvloop/blob/7bb12a174884b2ec8b3162a08564e5fb8a5c6b39/uvloop/loop.pyx#L2066
In that case, if
sock.close()
is not called (this pr changes that), uvloop seems to erroneously hold on to a ref to the transport when the underlying file descriptor has been relinquished to the os.It feels like at its core a bug in uvloop, however this at least works around it in
aiohttp
.Are there changes in behavior for the user?
No... Aside from this error not reproducing.
Is it a substantial burden for the maintainers to support this?
Unless I've made a mistake (it is a very small change though), I think this is a pure bug fix.
Related issue number
MagicStack/uvloop#653
Checklist
CONTRIBUTORS.txt
CHANGES/
foldername it
<issue_or_pr_num>.<type>.rst
(e.g.588.bugfix.rst
)if you don't have an issue number, change it to the pull request
number after creating the PR
.bugfix
: A bug fix for something the maintainers deemed animproper undesired behavior that got corrected to match
pre-agreed expectations.
.feature
: A new behavior, public APIs. That sort of stuff..deprecation
: A declaration of future API removals and breakingchanges in behavior.
.breaking
: When something public is removed in a breaking way.Could be deprecated in an earlier release.
.doc
: Notable updates to the documentation structure or buildprocess.
.packaging
: Notes for downstreams about unobvious side effectsand tooling. Changes in the test invocation considerations and
runtime assumptions.
.contrib
: Stuff that affects the contributor experience. e.g.Running tests, building the docs, setting up the development
environment.
.misc
: Changes that are hard to assign to any of the abovecategories.
Make sure to use full sentences with correct case and punctuation,
for example:
Use the past tense or the present tense a non-imperative mood,
referring to what's changed compared to the last released version
of this project.