asyncio proactor server leaks the accepted socket and stops accepting when transport creation fails
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
On the proactor event loop (the default on Windows), BaseProactorEventLoop._start_serving()'s loop() callback runs protocol_factory() and transport creation in the same callback that re-arms accept(), guarded only by except OSError / except CancelledError. When protocol_factory() or _make_ssl_transport() / _make_socket_transport() raises for an accepted connection:
- a non-
OSError(e.g. a failingprotocol_factory) propagates out ofloop(): the accepted socket is never closed (it leaks until garbage collection) and accept is not re-armed, so the server stops accepting new connections; - an
OSErroris caught as'Accept failed on a socket', which closes the listening socket, and still leaks the accepted socket.
This is the proactor counterpart of gh-155934 (selector accept) and gh-153133 (create_connection): an accepted socket must be closed when the transport is never created, and a per-connection failure must not tear down the listening socket or the accept loop.
Verified with mock-based tests in test_proactor_events (the same approach used for the selector fix in gh-155934), which run on all platforms.
CPython versions tested on:
CPython main
Operating systems tested on:
Windows (ProactorEventLoop)
Linked PRs
- gh-156366
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BaseProactorEventLoop._start_serving() and the mock-based tests in test_proactor_events. Reproduce the protocol or transport creation failure, then verify that the accepted socket is closed and the listening server continues accepting connections. Compare the existing work in linked PR gh-156366 before making changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100