Skip to content

Commit

Permalink
fix(submit_api): handle timeout and resubmit transaction
Browse files Browse the repository at this point in the history
- Added retry logic to handle request timeouts when posting CBOR data
  to the submit API.
- Introduced a delay with random sleep time between retries to avoid
  overwhelming the server.
  • Loading branch information
mkoura committed Nov 22, 2024
1 parent e338edf commit fcee7f3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cardano_node_tests/utils/submit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import json
import logging
import pathlib as pl
import random
import shutil
import time
import typing as tp

import requests
Expand Down Expand Up @@ -57,7 +59,19 @@ def post_cbor(cbor_file: clusterlib.FileType, url: str) -> requests.Response:
headers = {"Content-Type": "application/cbor"}
with open(cbor_file, "rb") as in_fp:
cbor_binary = in_fp.read()
response = requests.post(url, headers=headers, data=cbor_binary, timeout=10)

for i in range(5):
delay = False
if i > 0:
LOGGER.warning("Resubmitting transaction to submit-api.")
try:
response = requests.post(url, headers=headers, data=cbor_binary, timeout=20)
except requests.exceptions.ReadTimeout:
delay = True
else:
break
if delay:
time.sleep(random.random())
return response


Expand Down

0 comments on commit fcee7f3

Please sign in to comment.