qa refactor: wait_for_rpc_connection - Treat OSErrors the same
ConnectionResetError is an OSError as well (ECONNRESET), no reason to have a separate except-block for it. Also improves comments for other exceptions and make condition above more Pythonic.
This commit is contained in:
1 file changed
+13
-13
@@ -311,23 +311,23 @@ class TestNode():
|
|||||||
self.rpc_connected = True
|
self.rpc_connected = True
|
||||||
self.url = self.rpc.rpc_url
|
self.url = self.rpc.rpc_url
|
||||||
return
|
return
|
||||||
except JSONRPCException as e: # Initialization phase
|
except JSONRPCException as e:
|
||||||
|
# Suppress these as they are expected during initialization.
|
||||||
# -28 RPC in warmup
|
# -28 RPC in warmup
|
||||||
# -342 Service unavailable, RPC server started but is shutting down due to error
|
# -342 Service unavailable, could be starting up or shutting down
|
||||||
if e.error['code'] != -28 and e.error['code'] != -342:
|
if e.error['code'] not in [-28, -342]:
|
||||||
raise # unknown JSON RPC exception
|
raise # unknown JSON RPC exception
|
||||||
except ConnectionResetError:
|
|
||||||
# This might happen when the RPC server is in warmup, but shut down before the call to getblockcount
|
|
||||||
# succeeds. Try again to properly raise the FailedToStartError
|
|
||||||
pass
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ETIMEDOUT:
|
# Suppress similarly to the above JSONRPCException errors.
|
||||||
pass # Treat identical to ConnectionResetError
|
if e.errno not in [
|
||||||
elif e.errno == errno.ECONNREFUSED:
|
errno.ECONNRESET, # This might happen when the RPC server is in warmup,
|
||||||
pass # Port not yet open?
|
# but shut down before the call to getblockcount succeeds.
|
||||||
else:
|
errno.ETIMEDOUT, # Treat identical to ECONNRESET
|
||||||
|
errno.ECONNREFUSED # Port not yet open?
|
||||||
|
]:
|
||||||
raise # unknown OS error
|
raise # unknown OS error
|
||||||
except ValueError as e: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting
|
except ValueError as e:
|
||||||
|
# Suppress if cookie file isn't generated yet and no rpcuser or rpcpassword; bitcoind may be starting.
|
||||||
if "No RPC credentials" not in str(e):
|
if "No RPC credentials" not in str(e):
|
||||||
raise
|
raise
|
||||||
time.sleep(1.0 / poll_per_s)
|
time.sleep(1.0 / poll_per_s)
|
||||||
|
|||||||
Reference in new issue
Block a user