Fix SSLProtocol.connection_lost not being called when underlying socket is closed #639
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As as a follow up to python/cpython#118950, the fix to the issue in CPython's
asyncio
module seemed to translate quite well onto uvloop, and my failing tests effectively work both using the underlying socket streams and using higher level libraries such as aiohttp where the issue originally appeared.As a quick description the issue occurs when an underlying socket is broken (typically accompanied by a BrokenPipe error), in uvloop this translates to the
system.write
call returning some error code which is handled in the exact same way by callingfatal_error
as the sister implementation in asyncio. This implementation has a similar pitfall when the writer loop actively is ran in some kind of loop where thecall_soon
connection_lost
function that is supposed to mark the transport as closed (leading to an error being thrown) never is called, leading to some pretty annoying invalid state. But these details are mostly tested using asyncio but the same symptoms and underlying reasons seems to effect this implemention after some light testing, but there might be more to the story here.These changes are effectively a port of python/cpython#118960 with absolutely no difference except the more thorough tests reflecting the existing tests provided.
I have initially just skipped all asyncio tests as the upstream PR has yet to be merged but most likely we will see it in a future 3.12 release and newer.
Feel free to address any issues or things i've left out from here.