Skip to content
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 IndexError on failure to close socket #114

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

todddialpad
Copy link

What do these changes do?

It is possible for loop.sock_connect to fail in such a way that the wrapped socket no longer refers to a valid file descriptor. In this, the exception handler can fail on the attempt to call sock.close(). When this happens, start_connection can have sock == None and exceptions == []. This causes an IndexError because it assumes that exceptions always contains at least one exception instance.

Are there changes in behavior for the user?

I experienced crashes when handling connections with short timeouts.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

It is possible for `loop.sock_connect` to fail in such a way that the wrapped socket no longer refers to a valid file descriptor. In this, the exception handler can fail on the attempt to call `sock.close()`. When this happens, `start_connection` can have `sock == None` and `exceptions == []`. This causes an `IndexError` because it assumes that `exceptions` always contains at least one exception instance.
Fix for type checker
@bdraco
Copy link
Member

bdraco commented Nov 20, 2024

Would you please post the full trace you get when it raises IndexError in the opening text.

I'll try to get the code coverage reporting fixed

@bdraco
Copy link
Member

bdraco commented Nov 20, 2024

I bumped the codecov-action in #115 so hopefully codecov will work again once this PR has tests added

@webknjaz
Copy link
Member

Will this fix #112 / #93? If so, they should be linked. Plus, I hope for some tests covering the new code too.

@bdraco
Copy link
Member

bdraco commented Nov 20, 2024

codecov reporting should work now if you update with main

@todddialpad
Copy link
Author

Will this fix #112 / #93? If so, they should be linked. Plus, I hope for some tests covering the new code too.

Ah yes, I believe this is the same issue.

This started happening to us in production and the closest I have been able to come to a standalone test case is to generate statistically similar traffic patterns (which in our case means fairly aggressive timeouts). I haven't been able yet to craft a self-contained unit test.

chore: bump codecov-action to 5.0.3 (aio-libs#115)
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 97.44%. Comparing base (0653807) to head (fccce8d).

Files with missing lines Patch % Lines
src/aiohappyeyeballs/impl.py 40.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #114      +/-   ##
===========================================
- Coverage   100.00%   97.44%   -2.56%     
===========================================
  Files            5        5              
  Lines          227      235       +8     
  Branches        60       60              
===========================================
+ Hits           227      229       +2     
- Misses           0        6       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

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

Successfully merging this pull request may close these issues.

3 participants