Repository navigation
Description
Checklist
- I have verified that the issue exists against the
mainbranch of Celery. - This has already been asked to the discussions forum first.
- I have read the relevant section in the
contribution guide
on reporting bugs. - I have checked the issues list
for similar or identical bug reports. - I have checked the pull requests list
for existing proposed fixes. - I have checked the commit log
to find out if the bug was already fixed in the main branch. - I have included all related issues and possible duplicate issues
in this issue (If there are none, check this box anyway). - I have tried to reproduce the issue with pytest-celery and added the reproduction script below.
Mandatory Debugging Information
- I have included the output of
celery -A proj reportin the issue.
(if you are not able to do this, then at least specify the Celery
version affected). - I have verified that the issue exists against the
mainbranch of Celery. - I have included the contents of
pip freezein the issue. - I have included all the versions of all the external dependencies required
to reproduce this bug.
Related Issues and Possible Duplicates
Related Issues
- fix(cache): keep chords alive past result_expires #10830 added a startup warning for
result_chord_expiresover 30 days, for the same memcached rule. Nothing warns aboutresult_expires.
Possible Duplicates
- None
Environment & Settings
Celery version: main at 9c2f238 (5.7.0)
Steps to Reproduce
Required Dependencies
- Minimal Python Version: N/A or Unknown
- Minimal Celery Version: N/A or Unknown
- Minimal Kombu Version: N/A or Unknown
- Minimal Broker Version: N/A or Unknown
- Minimal Result Backend Version: memcached 1.6
- Minimal OS and/or Kernel Version: N/A or Unknown
- Minimal Broker Client Version: N/A or Unknown
- Minimal Result Backend Client Version: pymemcache 4.0.0
I ran it with Python 3.14 and the memory broker.
Minimally Reproducible Test Case
$ docker run -d -p 11211:11211 memcached:1.6from datetime import timedelta
from celery import Celery
from celery.contrib.testing.worker import start_worker
from celery.exceptions import TimeoutError
for days in (30, 31):
app = Celery('repro', broker='memory://',
backend='cache+memcached://127.0.0.1:11211/',
set_as_current=False)
app.conf.result_expires = timedelta(days=days)
@app.task(shared=False)
def add(x, y):
return x + y
with start_worker(app, pool='solo', perform_ping_check=False):
result = add.delay(2, 2)
try:
print(days, 'days:', result.get(timeout=5))
except TimeoutError:
print(days, 'days: get() timed out, state', result.state)Expected Behavior
result.get() returns 4 for both, and the result is kept for 31 days.
Actual Behavior
30 days: 4
31 days: get() timed out, state PENDING
The task ran and stored SUCCESS, but the result was gone at once. Nothing is logged.
The memcached protocol reads an expiry over 30 days (2,592,000 seconds) as an absolute Unix time, so 31 days in seconds (2,678,400) is a moment in January 1970, and memcached expires the key straight away. CacheBackend.set() passes result_expires as seconds (self.client.set(key, value, self.expires or 0)), and so does expire() (touch) and the chord counter's set() with result_chord_expires.
The result_expires docs don't mention the limit. The note in the result_chord_expires docs and the startup warning from #10830 only cover result_chord_expires, and the warning only fires when that setting is set, not when it falls back to a long result_expires.
Sending an expiry over 30 days as the Unix time it ends, int(time.time()) + seconds, fixes it. With that change, memcached reports a TTL of 31 days for the 31-day result, and of 400 days for a 400-day one.
Activity