Skip to content

Commit

Permalink
Fix an issue with the retry decorator (#330)
Browse files Browse the repository at this point in the history
By checking for cancellation before even calling the function, the retry
decorator was blocking final uploads in e.g. upload queues from even
starting.

This resulted in a very obscure bug where functions with retries would
seemingly work after the cancellation token was set, but in reality the
call stopped in the retry decorator and `None` was returned.
  • Loading branch information
mathialo authored May 21, 2024
1 parent d8f244d commit 0f98d81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## Next

### Fixed

* Fixed an issue with the `retry` decorator where functions would not be
called at all if the cancellation token was set. This resulted in errors
with for example upload queues.

## 7.1.6

Expand Down
5 changes: 4 additions & 1 deletion cognite/extractorutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,14 @@ def _retry_internal(
) -> _T2:
logger = logging.getLogger(__name__)

while tries and not cancellation_token.is_cancelled:
while tries:
try:
return f()

except Exception as e:
if cancellation_token.is_cancelled:
break

if isinstance(exceptions, tuple):
for ex_type in exceptions:
if isinstance(e, ex_type):
Expand Down

0 comments on commit 0f98d81

Please sign in to comment.