33import json
44import socket
55import random
6+ import sys
67from time import perf_counter
78from collections import defaultdict
89from typing import Dict , Optional , Tuple
@@ -197,6 +198,10 @@ def known_hubs(self):
197198 def jurisdiction (self ):
198199 return self .config .get ("jurisdiction" )
199200
201+ @property
202+ def exit_on_disconnect (self ):
203+ return self .config ["exit_on_disconnect" ]
204+
200205 def disconnect (self ):
201206 if self ._keepalive_task and not self ._keepalive_task .done ():
202207 self ._keepalive_task .cancel ()
@@ -373,7 +378,13 @@ def is_connected(self):
373378 def rpc (self , list_or_method , args , restricted = True , session : Optional [ClientSession ] = None ):
374379 if session or self .is_connected :
375380 session = session or self .client
376- return session .send_request (list_or_method , args )
381+ try :
382+ return session .send_request (list_or_method , args )
383+ except asyncio .TimeoutError :
384+ if self .exit_on_disconnect :
385+ log .error ("exiting on server disconnect" )
386+ sys .exit (1 )
387+ raise
377388 else :
378389 self ._urgent_need_reconnect .set ()
379390 raise ConnectionError ("Attempting to send rpc request when connection is not available." )
@@ -387,9 +398,16 @@ async def retriable_call(self, function, *args, **kwargs):
387398 try :
388399 return await function (* args , ** kwargs )
389400 except asyncio .TimeoutError :
390- log .warning ("Wallet server call timed out, retrying." )
401+ if self .exit_on_disconnect :
402+ log .error ("Wallet server call timed out, exiting on server disconnect." )
403+ sys .exit (1 )
404+ else :
405+ log .warning ("Wallet server call timed out, retrying." )
391406 except ConnectionError :
392407 log .warning ("connection error" )
408+ if self .exit_on_disconnect :
409+ log .error ("exiting on server disconnect" )
410+ sys .exit (1 )
393411 raise asyncio .CancelledError () # if we got here, we are shutting down
394412
395413 def _update_remote_height (self , header_args ):
0 commit comments