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