From f87fdad87c375bebfd7424dadd186e8490bfdaa6 Mon Sep 17 00:00:00 2001 From: Donncha O'Cearbhaill Date: Fri, 28 Apr 2017 18:41:33 +0200 Subject: [PATCH 1/2] Fix exception when an out-of-date descriptor is received This commit fixes a bug where `None` was returned from `Instance.update_descriptor()` rather than a boolean. If a received instance descriptor is older than the current descriptor it was discarded and None was returned. Instead `False` should be returned as the boolean result it later compared in `descriptor_received()`. s --- onionbalance/instance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionbalance/instance.py b/onionbalance/instance.py index ffa7c09..e12a8a1 100644 --- a/onionbalance/instance.py +++ b/onionbalance/instance.py @@ -125,7 +125,7 @@ def update_descriptor(self, parsed_descriptor): self.onion_address, parsed_descriptor.published, self.timestamp) - return + return False else: self.timestamp = parsed_descriptor.published From 349c620a1870e76def215b414150a5a7297a38ea Mon Sep 17 00:00:00 2001 From: Donncha O'Cearbhaill Date: Fri, 28 Apr 2017 19:29:52 +0200 Subject: [PATCH 2/2] Catch potential exceptions in the Stem event handler The Stem Tor control port library starts an event notifier thread and makes callbacks to the OnionBalance daemon with new events. If an unhandled exception occurs in an event callback the event notifier thread will crash. This will prevent OnionBalance getting new descriptor updates and eventual the onion service will go offline. This commit adds a `try: except` block around both event callback functions which should gracefully handle unexpected errors in the event notifier thread. --- onionbalance/eventhandler.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/onionbalance/eventhandler.py b/onionbalance/eventhandler.py index 7f919a4..182cf2d 100644 --- a/onionbalance/eventhandler.py +++ b/onionbalance/eventhandler.py @@ -28,7 +28,12 @@ def new_status(status_event): if status_event.status_type == stem.StatusType.GENERAL: if status_event.action == "CONSENSUS_ARRIVED": # Update the local view of the consensus in OnionBalance - consensus.refresh_consensus() + try: + consensus.refresh_consensus() + except Exception: + logger.exception("An unexpected exception occured in the " + "when processing the consensus update " + "callback.") @staticmethod def new_desc(desc_event): @@ -59,7 +64,11 @@ def new_desc_content(desc_content_event): return None # Send content to callback function which will process the descriptor - descriptor.descriptor_received(descriptor_text) + try: + descriptor.descriptor_received(descriptor_text) + except Exception: + logger.exception("An unexpected exception occured in the " + "new descriptor callback.") return None