[3.12] GH-110894: Call loop exception handler for exceptions in client_connected_cb (GH-111601) (#111632)

Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it..
(cherry picked from commit 229f44d353)
This commit is contained in:
Kumar Aditya 2023-11-02 13:48:49 +05:30 committed by GitHub
parent 99f0dd88b1
commit 9aa88290d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View file

@ -244,7 +244,19 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
res = self._client_connected_cb(reader,
self._stream_writer)
if coroutines.iscoroutine(res):
def callback(task):
exc = task.exception()
if exc is not None:
self._loop.call_exception_handler({
'message': 'Unhandled exception in client_connected_cb',
'exception': exc,
'transport': transport,
})
transport.close()
self._task = self._loop.create_task(res)
self._task.add_done_callback(callback)
self._strong_reader = None
def connection_lost(self, exc):