Does memcached validate that absolute expiration times are supplied in UTC?
0 reputation · 26 May 2025, 18:27 UTC
0 reputation · 26 May 2025, 18:27 UTC
Memcached stores expiration values either as a relative offset in seconds or as an absolute Unix timestamp, comparing the stored value against its own system clock. The protocol specification states that absolute times are interpreted as Unix time, but it does not define any timezone conversion or validation mechanism. Because the server clock runs in UTC, a client that supplies an absolute expiration derived from local wall-clock time without conversion may cause items to expire earlier or later than intended. There is currently no documented memcached configuration option to adjust for client time zones or to reject non-UTC absolute timestamps, leaving the responsibility entirely with the client.
Does memcached provide any configuration or protocol extension to validate or reject absolute expiration values that appear to be local wall-clock times rather than UTC Unix timestamps? When a client sends an absolute exptime derived from local time without conversion, does the server treat the value strictly as seconds since the Unix epoch, or are there any conditions under which the interpretation changes? Which documented memcached behaviors or version-specific changes should developers verify to confirm that absolute expirations remain tied to the server's UTC clock across different system timezone settings?
33275 reputation · 26 May 2025, 19:20 UTC
Memcached does not validate that absolute expiration values are supplied in UTC. It simply interprets any integer greater than 2,592,000 (30 days) as a literal Unix epoch timestamp and compares that value against the server’s own system clock. No protocol extension or configuration option exists to reject or convert non‑UTC timestamps.
exptime <= 2,592,000 (30 days), the value is treated as a relative offset in seconds from the current time.exptime > 2,592,000, the value is treated as a Unix epoch timestamp (seconds since 1970‑01‑01 UTC).There is no documented memcached configuration option that enforces UTC or rejects apparent local‑time expirations. The responsibility to supply a correct UTC timestamp lies entirely with the client. If a client mistakenly sends a local wall‑clock value without converting to UTC, the item will expire at the wrong instant, silently.
timedatectl status on Linux). The server uses this clock for all expiration calculations.memcached -V). All released versions up to the latest stable release exhibit the same 30‑day threshold behavior.To confirm the interpretation, you can store a key with an absolute expiration derived from your local time, then observe when it expires. For example, on a machine set to UTC‑5:
# Compute an absolute expiration 1 hour from now (local time)
exp=$(date -u -d '1 hour' +%s)
# Store the key with that expiration
printf 'set mykey 0 0 %d\r\nvalue\r\n' $exp | nc localhost 11211
# Wait 1 hour and check that the key is gone
# (or use a shorter offset to observe earlier/later behavior)
If the server clock is off by the timezone offset, the key will expire earlier or later than expected, illustrating that no conversion occurs on the server side.
Across all documented memcached protocol releases, the 30‑day threshold and the lack of timezone validation have remained unchanged. No version‑specific change alters how absolute expirations are tied to the server’s UTC clock.
To avoid unintended expirations, ensure that:
If you still observe discrepancies, double‑check the server’s date output and verify that the memcached process is running with the same timezone settings.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.