8000 gh-90871: fix connection backlog offset in asyncio by ChristianHrs · Pull Request #134392 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90871: fix connection backlog offset in asyncio #134392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
fix handle case with no exception
  • Loading branch information
ChristianHrs committed May 20, 2025
commit 0d595af36930374e21e534185059a18c3efc637a
33 changes: 19 additions & 14 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,18 +908,23 @@ def _done_callback(fut, cur_task=cur_task):
return outer


def _log_on_cancel_callback(inner):
if not inner.cancelled():
exc = inner.exception()
context = {
'message':
f'{exc.__class__.__name__} exception in shielded future',
'exception': exc,
'future': inner,
}
if inner._source_traceback:
context['source_traceback'] = inner._source_traceback
inner._loop.call_exception_handler(context)
def _log_on_exception(fut):
if fut.cancelled():
return

exc = fut.exception()
if exc is None:
return

context = {
'message':
f'{exc.__class__.__name__} exception in shielded future',
'exception': exc,
'future': fut,
}
if fut._source_traceback:
context['source_traceback'] = fut._source_traceback
fut._loop.call_exception_handler(context)


def shield(arg):
Expand Down Expand Up @@ -987,8 +992,8 @@ def _outer_done_callback(outer):
if not inner.done():
inner.remove_done_callback(_inner_done_callback)
# Keep only one callback to log on cancel
inner.remove_done_callback(_log_on_cancel_callback)
inner.add_done_callback(_log_on_cancel_callback)
inner.remove_done_callback(_log_on_exception)
inner.add_done_callback(_log_on_exception)

if cur_task is not None:
inner.add_done_callback(_clear_awaited_by_callback)
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,18 @@ def test_shield_cancel_outer(self):
self.assertTrue(outer.cancelled())
self.assertEqual(0, 0 if outer._callbacks is None else len(outer._callbacks))

def test_shield_cancel_outer_result(self):
mock_handler = mock.Mock()
self.loop.set_exception_handler(mock_handler)
inner = self.new_future(self.loop)
outer = asyncio.shield(inner)
test_utils.run_briefly(self.loop)
outer.cancel()
test_utils.run_briefly(self.loop)
inner.set_result(1)
test_utils.run_briefly(self.loop)
mock_handler.assert_not_called()

def test_shield_cancel_outer_exception(self):
mock_handler = mock.Mock()
self.loop.set_exception_handler(mock_handler)
Expand Down
Loading
0