From 5244a8e2d4f0a1e6a0562683960cf3d36f83add9 Mon Sep 17 00:00:00 2001 From: Xinyu Ma Date: Tue, 23 Mar 2021 03:54:32 -0700 Subject: [PATCH] app: Handle ConnectionResetError Fix: #22 --- src/ndn/app.py | 2 ++ src/ndn/transport/stream_socket.py | 2 +- src/ndn/types.py | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ndn/app.py b/src/ndn/app.py index 61c1a58..fbbb4a3 100644 --- a/src/ndn/app.py +++ b/src/ndn/app.py @@ -290,6 +290,8 @@ def run_forever(self, after_start: Awaitable = None) -> bool: A non-async wrapper of :meth:`main_loop`. :param after_start: the coroutine to start after connection to NFD is established. + :return: ``True`` if the connection is shutdown not by ``Ctrl+C``. + For example, manually or by the other side. :examples: .. code-block:: python3 diff --git a/src/ndn/transport/stream_socket.py b/src/ndn/transport/stream_socket.py index 98bb153..97cdbed 100644 --- a/src/ndn/transport/stream_socket.py +++ b/src/ndn/transport/stream_socket.py @@ -65,7 +65,7 @@ async def run(self): bio.write(await self.reader.readexactly(siz)) buf = bio.getvalue() aio.ensure_future(self.callback(typ, buf)) - except aio.IncompleteReadError: + except (aio.IncompleteReadError, ConnectionResetError): self.shutdown() def send(self, data: bytes): diff --git a/src/ndn/types.py b/src/ndn/types.py index b684df8..6860260 100644 --- a/src/ndn/types.py +++ b/src/ndn/types.py @@ -43,6 +43,14 @@ class InterestTimeout(Exception): class InterestCanceled(Exception): """ Raised when an Interest is cancelled due to the loss of connection to NFD. + + .. note:: + A very large packet may cause NFD shutting down the connection. + More specifically, + + - The face is shutdown. + - All pending Interests are cancelled with this exception. + - ``App.run_forever()`` returns ``True``. """ pass