python / python/cpython

asyncio proactor server leaks the accepted socket and stops accepting when transport creation fails

Open
#156,365 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OS-windows stdlib topic-asyncio type-bug
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 failing protocol_factory) propagates out of loop(): 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 OSError is 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.