Repository navigation
Send memcached an expiry over 30 days as an absolute time - #11120
Open
MehrazRumman wants to merge 5 commits into
Open
MehrazRumman wants to merge 5 commits into
MehrazRumman wants to merge 5 commits into
Conversation
Memcached reads an expiry over 30 days as an absolute Unix time. The cache backend passed result_expires and result_chord_expires to it as seconds, so with result_expires=timedelta(days=31) every result expired as soon as it was stored, and AsyncResult.get() never returned. Send an expiry over 30 days as the Unix time it ends, in set(), in expire() and for the chord counter. Shorter expiries and 0 are sent as before.
The cache backend warned at startup that memcached would expire chord keys at once when result_chord_expires was over 30 days, and the docs said to keep it at 30 days or less. Since the previous commit sends such an expiry as an absolute time, the keys live as long as configured, so remove the warning and the note.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11120 +/- ##
=======================================
Coverage 91.26% 91.26%
=======================================
Files 153 153
Lines 21788 21790 +2
Branches 2702 2703 +1
=======================================
+ Hits 19885 19887 +2
Misses 1603 1603
Partials 300 300
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
This was referenced Nov 18, 2026
auvipy
self-requested a review
November 19, 2026 03:38
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Before submitting this pull request, please review our contributing
guidelines & [Anti AI spamming Guidelines] (#10932). Before opening an AI based PR make sure you asked
in the discussion forum or in the related open issues first.
Description
Fixes #11119
Memcached reads an expiry over 30 days as an absolute Unix time. The cache backend passed
result_expiresandresult_chord_expiresas seconds, so withresult_expires=timedelta(days=31)every result expired as soon as it was stored, andAsyncResult.get()never returned. Nothing was logged._memcached_expires()sends an expiry over 30 days as the Unix time it ends,int(time.time()) + seconds. It's used inCacheBackend.set(),expire()(touch) and for the chord counter in_apply_chord_incr(). Shorter expiries, and 0 for no expiry, are sent as before.result_chord_expiresover 30 days, and the docs note saying to keep it at 30 days or less, are removed, since such keys now last as long as configured. Theloggerthat only that warning used goes with it.Only
celery/backends/cache.pychanges, and the in-memoryDummyClientignores expiries as before.#11072, which is open, caps its new chord keys at 30 days on memcached with
min(..., MAX_RELATIVE_EXPIRES), and its docs say "at most 30 days". The two PRs work together as they are. Once this one is in, that cap could go, with_memcached_expires()used instead.Tests
Against memcached 1.6 in Docker, with pymemcache 4.0.0 and Python 3.14. The task test uses the memory broker and an in-process solo worker. The TTL is what
mg <key> treports right after the result is stored:result_expiresmain: taskget()get()New unit tests in
t/unit/backends/test_cache.pycheck the expiry thatset(),expire()and the chord counter send. The three cases over 30 days fail onmain(checked with onlyimport timeadded tomain'scache.py, so the patch target exists) and pass here. Each of these changes makes one of them fail:>changed to>=, and the old expiry restored inset(),expire()or the chord counter.pytest t/unit/backends/test_cache.py t/unit/backends/test_base.py: all pass, apart fromtest_store_result_parent_id[msgpack], which fails the same way onmainbecausemsgpackisn't installed here. pre-commit passes on the changed files.Not run: the integration and smoke suites. The smoke suite's memcached tests use 1 day or less, which this doesn't change.