From 58d0a4573817d70c9f00e5553ed135be420771ef Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 24 Oct 2018 13:04:03 +0100 Subject: [PATCH] issue #76: quieten routing errors. Receiving DEL_ROUTE without a corresponding ADD_ROUTE is now legit behaviour, so don't print an error in this case. Don't print an error for dropped messages if the reply_to indicates the sender doesn't care about a response (dead and no_reply) --- mitogen/core.py | 5 +++-- mitogen/parent.py | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index 5d509152..a5270ec7 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -1870,8 +1870,9 @@ class Router(object): dead = False if out_stream is None: - LOG.error('%r: no route for %r, my ID is %r', - self, msg, mitogen.context_id) + if msg.reply_to not in (0, IS_DEAD): + LOG.error('%r: no route for %r, my ID is %r', + self, msg, mitogen.context_id) dead = True if in_stream and self.unidirectional and not dead and \ diff --git a/mitogen/parent.py b/mitogen/parent.py index 5e0157d6..9e878e3f 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -1598,11 +1598,12 @@ class Router(mitogen.core.Router): def del_route(self, target_id): LOG.debug('%r.del_route(%r)', self, target_id) - try: - del self._stream_by_id[target_id] - except KeyError: - LOG.error('%r: cant delete route to %r: no such stream', - self, target_id) + # DEL_ROUTE may be sent by a parent if it knows this context sent + # messages to a peer that has now disconnected, to let us raise + # 'disconnect' event on the appropriate Context instance. In that case, + # we won't a matching _stream_by_id entry for the disappearing route, + # so don't raise an error for a missing key here. + self._stream_by_id.pop(target_id, None) def get_module_blacklist(self): if mitogen.context_id == 0: