Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3006d6e
fix proactor error hang
graingert Aug 31, 2026
60187dd
Merge branch 'main' into fix-proactor-error-hang
graingert Sep 4, 2026
d57cb23
fix DatagramTransport when errror_recieved calls sendto
graingert Sep 4, 2026
f843371
gh-156920: fix ProactorEventLoop datagram transports drop buffered da…
graingert Sep 4, 2026
bb80478
Merge branch 'main' of github.com:python/cpython into fix-proactor-er…
graingert Sep 5, 2026
0db5dd3
Merge branch 'fix-proactor-error-hang' into fix-proactor-close-flush
graingert Sep 5, 2026
37a9b5b
Update Lib/asyncio/proactor_events.py
graingert Sep 5, 2026
d8f9aae
Merge branch 'main' into fix-proactor-error-hang
graingert Sep 6, 2026
9eda8d0
don't resume a closed transport
graingert Sep 6, 2026
9fcd45c
Merge branch 'main' into fix-proactor-error-hang
graingert Sep 7, 2026
4822ab7
add test for close called in error_recieved
graingert Sep 7, 2026
ce2168b
Merge branch 'fix-proactor-error-hang' into fix-proactor-close-flush
graingert Sep 7, 2026
b52b945
Revert "add test for close called in error_recieved"
graingert Sep 7, 2026
d4ee8a9
add test_datagram_write_error_close_from_callback
graingert Sep 7, 2026
b74ffb3
use SHORT_TIMEOUT instead of hardcoded 10
graingert Sep 11, 2026
01b328a
Merge branch 'main' into fix-proactor-error-hang
graingert Sep 11, 2026
b43d1fc
Merge branch 'fix-proactor-error-hang' into fix-proactor-close-flush
graingert Sep 11, 2026
55706b8
drop datagram write-error tests that pass without the fix
graingert Sep 11, 2026
92d347c
Merge branch 'main' into fix-proactor-close-flush
graingert Sep 11, 2026
757a9fb
check self._closing in Datagram _loop_reading
graingert Sep 11, 2026
386268a
Apply suggestion from @kumaraditya303
graingert Sep 12, 2026
5d6ac18
Merge branch 'main' into fix-proactor-close-flush
graingert Sep 12, 2026
1adb870
replace arm with schedule
graingert Sep 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test for close called in error_recieved
  • Loading branch information
graingert committed Sep 7, 2026
commit 4822ab71e974da0b38c284c7d86c15eee0ea9149
40 changes: 40 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,46 @@ def connection_lost(self, exc):
loop.run_until_complete(asyncio.wait_for(protocol.lost, 10))
self.assertTrue(protocol.errors)

def test_datagram_write_error_close_from_callback(self):
# See https://github.com/python/cpython/issues/156920: an
# error_received() callback that closes the transport while data
# is still queued behind the failing write must still result in
# connection_lost() being called eventually, instead of leaving
# the transport (and its buffered data) hanging forever.
loop = self.loop

class Protocol(asyncio.DatagramProtocol):
def connection_made(self, transport):
self.transport = transport
self.errors = []
self.lost = loop.create_future()

def error_received(self, exc):
self.errors.append(exc)
self.transport.close()

def connection_lost(self, exc):
if not self.lost.done():
self.lost.set_result(exc)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setblocking(False)
sock.bind(('127.0.0.1', 0))
transport, protocol = loop.run_until_complete(
loop.create_datagram_endpoint(Protocol, sock=sock))
addr = sock.getsockname()

# queue an oversized (failing) datagram followed by one that
# would otherwise succeed, so the buffer is still non-empty when
# error_received() closes the transport.
oversized = b'\x00' * 70000
transport.sendto(oversized, addr)
transport.sendto(b'queued', addr)

loop.run_until_complete(asyncio.wait_for(protocol.lost, 10))
self.assertTrue(protocol.errors)
self.assertIsInstance(protocol.errors[0], OSError)

def test_datagram_recvfrom_connection_reset_recovers(self):
# gh-127057: a UDP socket that sent a datagram to an address that
# wasn't listening can raise ConnectionResetError on a later
Expand Down
Loading