Skip to content

SG-38213 Prevent unexpected retries on error #379

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Flow Production Tracking Python API Changelog

Here you can see the full list of changes between each Python API release.

v3.8.5 (2025 Xxx X)
===================

- We don't want to retry on general exceptions (e.g. timeout or remote disconnection)
because we might send a resource modification request (create, batch create, etc) and
we can end up duplicating things.

v3.8.4 (2025 Jun 11)
====================

Expand Down
7 changes: 3 additions & 4 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3938,11 +3938,10 @@ def _make_call(self, verb, path, body, headers):
if attempt == max_rpc_attempts:
LOG.debug("Request failed. Giving up after %d attempts." % attempt)
raise
except Exception:
except Exception as e:
self._close_connection()
if attempt == max_rpc_attempts:
LOG.debug("Request failed. Giving up after %d attempts." % attempt)
raise
LOG.debug(f"Request failed. Reason: {e}", exc_info=True)
Comment on lines 3942 to +3943
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

Catching all Exception means non-SSL errors will still trigger retry logic. Limit retry handling to specific SSL errors (e.g. SSLEOFError, SSLHandshakeError) and re-raise other exceptions immediately.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

False, we handle this on the first two except blocks.

raise

LOG.debug(
"Request failed, attempt %d of %d. Retrying in %.2f seconds..."
Expand Down
36 changes: 1 addition & 35 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,42 +2223,8 @@ def test_make_call_retry(self, mock_request):

self.assertEqual(cm2.exception.args[0], "not working")
log_content = "\n".join(cm1.output)
for i in [1, 2]:
self.assertIn(
f"Request failed, attempt {i} of 3. Retrying",
log_content,
)
self.assertIn(
"Request failed. Giving up after 3 attempts.",
log_content,
)

# Then, make the exception happening only once and prove the
# retry works
def my_side_effect(*args, **kwargs):
try:
if my_side_effect.counter < 1:
raise Exception("not working")

return mock.DEFAULT
finally:
my_side_effect.counter += 1

my_side_effect.counter = 0
mock_request.side_effect = my_side_effect
with self.assertLogs("shotgun_api3", level="DEBUG") as cm:
self.assertIsInstance(
self.sg.info(),
dict,
)

log_content = "\n".join(cm.output)
self.assertIn(
"Request failed, attempt 1 of 3. Retrying",
log_content,
)
self.assertNotIn(
"Request failed, attempt 2 of 3. Retrying",
"Request failed. Reason: not working",
log_content,
)

Expand Down
10 changes: 1 addition & 9 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,9 @@ def test_network_retry(self):
with mock.patch("time.sleep") as mock_sleep:
self.assertRaises(httplib2.HttpLib2Error, self.sg.info)
self.assertTrue(
self.sg.config.max_rpc_attempts == self.sg._http_request.call_count,
self.sg._http_request.call_count == 1,
"Call is repeated",
)
# Ensure that sleep was called with the retry interval between each attempt
attempt_interval = self.sg.config.rpc_attempt_interval / 1000.0
calls = [mock.callargs(((attempt_interval,), {}))]
calls *= self.sg.config.max_rpc_attempts - 1
self.assertTrue(
mock_sleep.call_args_list == calls,
"Call is repeated at correct interval.",
)

def test_set_retry_interval(self):
"""Setting the retry interval through parameter and environment variable works."""
Expand Down