mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-25 06:55:32 +01:00
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:
@@ -311,23 +311,23 @@ class TestNode():
|
||||
self.rpc_connected = True
|
||||
self.url = self.rpc.rpc_url
|
||||
return
|
||||
except JSONRPCException as e: # Initialization phase
|
||||
except JSONRPCException as e:
|
||||
# Suppress these as they are expected during initialization.
|
||||
# -28 RPC in warmup
|
||||
# -342 Service unavailable, RPC server started but is shutting down due to error
|
||||
if e.error['code'] != -28 and e.error['code'] != -342:
|
||||
# -342 Service unavailable, could be starting up or shutting down
|
||||
if e.error['code'] not in [-28, -342]:
|
||||
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:
|
||||
if e.errno == errno.ETIMEDOUT:
|
||||
pass # Treat identical to ConnectionResetError
|
||||
elif e.errno == errno.ECONNREFUSED:
|
||||
pass # Port not yet open?
|
||||
else:
|
||||
# Suppress similarly to the above JSONRPCException errors.
|
||||
if e.errno not in [
|
||||
errno.ECONNRESET, # This might happen when the RPC server is in warmup,
|
||||
# but shut down before the call to getblockcount succeeds.
|
||||
errno.ETIMEDOUT, # Treat identical to ECONNRESET
|
||||
errno.ECONNREFUSED # Port not yet open?
|
||||
]:
|
||||
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):
|
||||
raise
|
||||
time.sleep(1.0 / poll_per_s)
|
||||
|
||||
Reference in New Issue
Block a user