diff options
author | Kumar Aditya <kumaraditya@python.org> | 2023-11-02 08:18:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 08:18:49 (GMT) |
commit | 9aa88290d82e2808eed84e7a63d0bf9623f84f53 (patch) | |
tree | 16998db48c9582155cb69b515c3f31c4e29199a8 /Lib/asyncio/streams.py | |
parent | 99f0dd88b1ef8309a4e2a23a51bb47e18e1d81f3 (diff) | |
download | cpython-9aa88290d82e2808eed84e7a63d0bf9623f84f53.zip cpython-9aa88290d82e2808eed84e7a63d0bf9623f84f53.tar.gz cpython-9aa88290d82e2808eed84e7a63d0bf9623f84f53.tar.bz2 |
[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 229f44d353c71185414a072017f46f125676bdd6)
Diffstat (limited to 'Lib/asyncio/streams.py')
-rw-r--r-- | Lib/asyncio/streams.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index aff081a..f63eeca 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -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): |