Skip to content

Commit

Permalink
actually exit on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
eukreign committed Aug 30, 2022
1 parent 888bd85 commit 8bd7008
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lbry/wallet/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import socket
import random
import sys
from time import perf_counter
from collections import defaultdict
from typing import Dict, Optional, Tuple
Expand Down Expand Up @@ -197,6 +198,10 @@ def known_hubs(self):
def jurisdiction(self):
return self.config.get("jurisdiction")

@property
def exit_on_disconnect(self):
return self.config["exit_on_disconnect"]

def disconnect(self):
if self._keepalive_task and not self._keepalive_task.done():
self._keepalive_task.cancel()
Expand Down Expand Up @@ -373,7 +378,13 @@ def is_connected(self):
def rpc(self, list_or_method, args, restricted=True, session: Optional[ClientSession] = None):
if session or self.is_connected:
session = session or self.client
return session.send_request(list_or_method, args)
try:
return session.send_request(list_or_method, args)
except asyncio.TimeoutError:
if self.exit_on_disconnect:
log.error("exiting on server disconnect")
sys.exit(1)
raise
else:
self._urgent_need_reconnect.set()
raise ConnectionError("Attempting to send rpc request when connection is not available.")
Expand All @@ -387,9 +398,16 @@ async def retriable_call(self, function, *args, **kwargs):
try:
return await function(*args, **kwargs)
except asyncio.TimeoutError:
log.warning("Wallet server call timed out, retrying.")
if self.exit_on_disconnect:
log.error("Wallet server call timed out, exiting on server disconnect.")
sys.exit(1)
else:
log.warning("Wallet server call timed out, retrying.")
except ConnectionError:
log.warning("connection error")
if self.exit_on_disconnect:
log.error("exiting on server disconnect")
sys.exit(1)
raise asyncio.CancelledError() # if we got here, we are shutting down

def _update_remote_height(self, header_args):
Expand Down

0 comments on commit 8bd7008

Please sign in to comment.