Skip to content

Commit

Permalink
Use different log levels for handler errors and closed/broken connect…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
borzunov committed Aug 20, 2021
1 parent 70e9faa commit 3789b7e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions hivemind/p2p/p2p_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,17 @@ async def _read_stream() -> P2P.TInputStream:
async def _process_stream() -> None:
try:
async for response in handler(_read_stream(), context):
await P2P.send_protobuf(response, writer)
try:
await P2P.send_protobuf(response, writer)
except Exception:
# The connection is unexpectedly closed by the caller or broken.
# The loglevel is DEBUG since the actual error will be reported on the caller
logger.debug("Exception while sending response:", exc_info=True)
break
except Exception as e:
logger.warning("Exception while processing stream and sending responses:", exc_info=True)
# Sometimes `e` is a connection error, so we won't be able to report the error to the caller
logger.warning("Handler failed with the exception:", exc_info=True)
with suppress(Exception):
# Sometimes `e` is a connection error, so it is okay if we fail to report `e` to the caller
await P2P.send_protobuf(RPCError(message=str(e)), writer)

with closing(writer):
Expand Down

0 comments on commit 3789b7e

Please sign in to comment.