Skip to content

fix(utils): never sleep longer than interval_max in retry_over_time - #2588

Open
abhijeet117 wants to merge 8 commits into
celery:mainfrom
abhijeet117:fix/retry-interval-max-clamp
Open

fix(utils): never sleep longer than interval_max in retry_over_time#2588
abhijeet117 wants to merge 8 commits into
celery:mainfrom
abhijeet117:fix/retry-interval-max-clamp

Conversation

@abhijeet117

Copy link
Copy Markdown

Summary

retry_over_time() could sleep longer than interval_max because its backoff range is built as fxrange(interval_start, interval_max + interval_start, interval_step, repeatlast=True), and fxrange yields every value up to and including its stop before repeating the last one forever. The steady-state sleep therefore exceeded interval_max by construction (defaults 2/2/30 reached 32s). This clamps the computed sleep at interval_max before sleeping, matching the documented contract. Fixes #914.

Testing

  • Added test_never_sleeps_longer_than_interval_max, which captures per-retry sleep totals with a patched sleep and asserts they never exceed interval_max. It failed before the fix (max sleep 7.0 > 6) and passes after (max exactly 6.0).
  • Full t/unit suite run after the fix matches the pristine baseline.

Checklist

  • bug reproduced before fix
  • root cause identified
  • bug fixed
  • tests passed

retry_over_time builds its interval range with fxrange(interval_start,
interval_max + interval_start, interval_step, repeatlast=True), so the
steady-state value repeats above interval_max by construction (with the
default 2/2/30 it reaches 32 seconds). Clamp the computed sleep time at
interval_max to honor the documented contract.

Fixes celery#914
@auvipy
auvipy requested review from auvipy and a lite review from Copilot August 26, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes kombu.utils.functional.retry_over_time() so its computed sleep time never exceeds the interval_max argument, aligning runtime behavior with the documented contract and addressing the overflow described in #914.

Changes:

  • Clamp the computed “time to sleep” (tts) to interval_max before sleeping.
  • Add a unit test that records total slept time per retry attempt and asserts it never exceeds interval_max.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
kombu/utils/functional.py Clamp tts to interval_max to prevent fxrange-generated overflow beyond the configured maximum.
t/unit/utils/test_functional.py Add regression test ensuring per-retry sleep never exceeds interval_max when retrying.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@auvipy auvipy added this to the 5.7.0 milestone Aug 31, 2026

@auvipy auvipy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is it possible to add integration test for this as well?

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.17%. Comparing base (78b528b) to head (ba1acf8).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2588   +/-   ##
=======================================
  Coverage   83.17%   83.17%           
=======================================
  Files          79       79           
  Lines       10636    10637    +1     
  Branches     1243     1243           
=======================================
+ Hits         8846     8847    +1     
  Misses       1584     1584           
  Partials      206      206           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread kombu/utils/functional.py Outdated
Comment on lines +329 to +331
# the last value of fxrange can be above interval_max,
# as its stop argument is inflated by interval_start.
tts = min(tts, float(interval_max))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@abhijeet117 please cross check this

poolik and others added 4 commits September 1, 2026 09:52
…2465)

* Add missing retry to publisher.publish in gcpubsub _put

The publish call in _put was missing a retry parameter, unlike
_put_fanout which already had one. This could cause transient
failures to propagate immediately instead of being retried.

* Add unit tests for retry parameter in gcpubsub _put

---------

Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
from_dict passed a hardcoded subset of kwargs to Queue, so alias, no_declare, expires, message_ttl, max_length, max_length_bytes and max_priority were silently lost on a round-trip through as_dict. Forward every attribute declared in Queue.attrs instead, so options added later are preserved automatically. Closes celery#1236.

Co-authored-by: VXNCXNX <VXNCXNX@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
TopicExchange documents '*' as any single word, but compiled it to
'.*?[^\.]', whose leading '.*?' also matches dots. Only the final
character was constrained, so 'a.*.c' matched 'a.b.x.c' and every
virtual transport delivered messages to queues that never bound them.

Compile '*' to a single dot-free word instead. '#' is unchanged.

Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
@abhijeet117

Copy link
Copy Markdown
Author

@auvipy Added the interval_max regression coverage and validated the errback-observed interval is clamped before sleeping.

@abhijeet117
abhijeet117 requested a review from auvipy September 1, 2026 04:25
@auvipy

auvipy commented Sep 1, 2026

Copy link
Copy Markdown
Member

thanks for additional unit tests. but I was talking about addtional integration tests in another file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autoretry interval may overflow interval_max setting

6 participants