Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry mechanism to better handle ConnectionError #420

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
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
36 changes: 19 additions & 17 deletions geti_sdk/http_session/geti_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,25 @@ def get_rest_response(
else:
self.headers.pop("x-geti-csrf-protection", "")

try:
response = self.request(**request_params, proxies=self._proxies)
except requests.exceptions.SSLError as error:
raise requests.exceptions.SSLError(
f"Connection to Intel® Geti™ server at '{self.config.host}' failed, "
f"the server address can be resolved but the SSL certificate could not "
f"be verified. \n Full error description: {error.args[-1]}"
)
except ConnectionError as conn_error:
if conn_error.args[0] == "Connection aborted.":
# We fake a response and try to establish a
# new connection by re-authenticating
response = Response()
response.status_code = 401
response.raw = conn_error.args[-1]
else:
raise conn_error
# Make the request, retrying a maximum of 5 times in case of connection errors
retries = 5
last_conn_error: Optional[ConnectionError] = None
while retries:
try:
response = self.request(**request_params, proxies=self._proxies)
break
except requests.exceptions.SSLError as error:
raise requests.exceptions.SSLError(
f"Connection to Intel® Geti™ server at '{self.config.host}' failed, "
f"the server address can be resolved but the SSL certificate could not "
f"be verified. \n Full error description: {error.args[-1]}"
)
except ConnectionError as conn_error:
last_conn_error = conn_error
retries -= 1

if last_conn_error is not None:
raise last_conn_error

response_content_type = response.headers.get("Content-Type", [])
if (
Expand Down
3 changes: 3 additions & 0 deletions tests/pre-merge/integration/test_geti.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ def test_post_inference_hooks(
image_np = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
_ = deployment.infer(image_np)

# Small delay to ensure that the hooks have time to run
time.sleep(1)

dataset_client = DatasetClient(
session=fxt_geti.session,
workspace_id=fxt_geti.workspace_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def coords_to_xmin_xmax_width_height(
return x1, y1, x2 - x1, y2 - y1


@pytest.mark.JobsComponent
class TestInferenceResultsToPredictionConverter:
def test_classification_to_prediction_converter(self, fxt_label_schema_factory):
# Arrange
Expand Down
Loading