Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

Commit

Permalink
Catch potential exceptions in the Stem event handler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DonnchaC committed Apr 28, 2017
1 parent f87fdad commit 349c620
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions onionbalance/eventhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 349c620

Please sign in to comment.