diff options
author | Kumar Aditya <kumaraditya@python.org> | 2023-11-02 07:38:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 07:38:18 (GMT) |
commit | 229f44d353c71185414a072017f46f125676bdd6 (patch) | |
tree | 0319ee2c69cf53eb87a11b43705f09fc2c695310 /Lib/asyncio/streams.py | |
parent | 794dff2fb1d9efe73a724640192c34b25f4fae85 (diff) | |
download | cpython-229f44d353c71185414a072017f46f125676bdd6.zip cpython-229f44d353c71185414a072017f46f125676bdd6.tar.gz cpython-229f44d353c71185414a072017f46f125676bdd6.tar.bz2 |
GH-110894: Call loop exception handler for exceptions in client_connected_cb (#111601)
Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it.
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 bc84e53..f82b10c 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -245,7 +245,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): |