Skip to content

Commit

Permalink
app: Handle ConnectionResetError
Browse files Browse the repository at this point in the history
Fix: #22
  • Loading branch information
zjkmxy committed Mar 23, 2021
1 parent 3710b0d commit 5244a8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ndn/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ndn/transport/stream_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions src/ndn/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5244a8e

Please sign in to comment.