Skip to content

Commit

Permalink
Fix an unhandled value error encountered sometimes
Browse files Browse the repository at this point in the history
(when contacting peers)
  • Loading branch information
davidlougheed committed Jun 17, 2020
1 parent c8421dd commit 2dfabfb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions bento_federation_service/peers/manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import sys
import tornado.gen

from datetime import datetime, timedelta
Expand Down Expand Up @@ -81,11 +82,16 @@ async def peer_worker(self, peers: Set[str], peers_to_check: Queue, peers_to_che
peer_peers = r["peers"]

except IndexError:
print(f"[{SERVICE_NAME}] Error: Invalid 200 response returned by {peer}.", flush=True)

except HTTPError as e:
print(f"[{SERVICE_NAME}] Peer contact error for {peer} ({str(e)})", flush=True)
self.last_errored[peer] = datetime.now().timestamp()
print(f"[{SERVICE_NAME} {datetime.now()}] [ERROR] Invalid 200 response returned by {peer}.", flush=True,
file=sys.stderr)

except (HTTPError, ValueError) as e:
# HTTPError: Standard 400s/500s
# ValueError: ex. Unsupported url scheme: api/federation/peers
now = datetime.now()
print(f"[{SERVICE_NAME} {now}] [ERROR] Peer contact error for {peer} ({str(e)})", flush=True,
file=sys.stderr)
self.last_errored[peer] = now.timestamp()

# Incorporate the peer's peer list into the current set of peers
peers = peers.union(peer_peers)
Expand Down

0 comments on commit 2dfabfb

Please sign in to comment.