From fcee7f3e784acfbd2c685eacbfbd49825df131d9 Mon Sep 17 00:00:00 2001 From: Martin Kourim Date: Fri, 22 Nov 2024 18:50:59 +0100 Subject: [PATCH] fix(submit_api): handle timeout and resubmit transaction - 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. --- cardano_node_tests/utils/submit_api.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cardano_node_tests/utils/submit_api.py b/cardano_node_tests/utils/submit_api.py index 80b003305..794ae896e 100644 --- a/cardano_node_tests/utils/submit_api.py +++ b/cardano_node_tests/utils/submit_api.py @@ -5,7 +5,9 @@ import json import logging import pathlib as pl +import random import shutil +import time import typing as tp import requests @@ -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