Skip to content

Commit 5244a8e

Browse files
committed
app: Handle ConnectionResetError
Fix: #22
1 parent 3710b0d commit 5244a8e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/ndn/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ def run_forever(self, after_start: Awaitable = None) -> bool:
290290
A non-async wrapper of :meth:`main_loop`.
291291
292292
:param after_start: the coroutine to start after connection to NFD is established.
293+
:return: ``True`` if the connection is shutdown not by ``Ctrl+C``.
294+
For example, manually or by the other side.
293295
294296
:examples:
295297
.. code-block:: python3

src/ndn/transport/stream_socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def run(self):
6565
bio.write(await self.reader.readexactly(siz))
6666
buf = bio.getvalue()
6767
aio.ensure_future(self.callback(typ, buf))
68-
except aio.IncompleteReadError:
68+
except (aio.IncompleteReadError, ConnectionResetError):
6969
self.shutdown()
7070

7171
def send(self, data: bytes):

src/ndn/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class InterestTimeout(Exception):
4343
class InterestCanceled(Exception):
4444
"""
4545
Raised when an Interest is cancelled due to the loss of connection to NFD.
46+
47+
.. note::
48+
A very large packet may cause NFD shutting down the connection.
49+
More specifically,
50+
51+
- The face is shutdown.
52+
- All pending Interests are cancelled with this exception.
53+
- ``App.run_forever()`` returns ``True``.
4654
"""
4755
pass
4856

0 commit comments

Comments
 (0)