Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/ethereum_test_rpc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,24 @@ def post_request(
}
headers = base_header | extra_headers

logger.debug(f"Sending RPC request, timeout is set to {timeout}...")
response = requests.post(self.url, json=payload, headers=headers, timeout=timeout)
response.raise_for_status()
response_json = response.json()

if "error" in response_json:
raise JSONRPCError(**response_json["error"])

assert "result" in response_json, "RPC response didn't contain a result field"
result = response_json["result"]
return result
for attempt in range(6):
try:
logger.debug(f"Sending RPC request, timeout is set to {timeout}...")
response = requests.post(self.url, json=payload, headers=headers, timeout=timeout)
response.raise_for_status()
response_json = response.json()
if "error" in response_json:
raise JSONRPCError(**response_json["error"])

assert "result" in response_json, "RPC response didn't contain a result field"
result = response_json["result"]
return result
except requests.ConnectionError as e:
if ("Connection refused" in str(e) or "Errno 111" in str(e)) and attempt < 4:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has an off by one:

Suggested change
if ("Connection refused" in str(e) or "Errno 111" in str(e)) and attempt < 4:
if ("Connection refused" in str(e) or "Errno 111" in str(e)) and attempt < 5:

if attempt > 0:
time.sleep(1.0)
continue
raise


class EthRPC(BaseRPC):
Expand Down
Loading