Bug report
Bug description:
Originally reported in aio-libs/aiohttp#10617 (comment)
To make this happen:
Call loop.sock_connect and cancel it before the socket is connected.
Because _sock_write_done is called via add_done_callback it gets called in the next iteration of the event loop on cancellation.
sock_connect will return before _sock_write_done is called which means the writer has not been removed yet and can get reused.
Additionally, this makes the close in
unsafe because on cancellation the socket gets closed before the writer is removed so the fd can get reused
CPython versions tested on:
3.10 but the same code exists for 3.13+
Operating systems tested on:
Linux
Bug report
Bug description:
To make this happen:
Call
loop.sock_connectand cancel it before the socket is connected.Because
_sock_write_doneis called viaadd_done_callbackit gets called in the next iteration of the event loop on cancellation.cpython/Lib/asyncio/selector_events.py
Line 658 in 9c7ef0c
sock_connectwill return before_sock_write_doneis called which means the writer has not been removed yet and can get reused.Additionally, this makes the
closeincpython/Lib/asyncio/base_events.py
Line 1047 in 9c7ef0c
CPython versions tested on:
3.10 but the same code exists for 3.13+
Operating systems tested on:
Linux