If I put the computer to sleep, the clock doesn't advance until the system resumes. As a result, the clock drifts w.r.t system clock. If I check the entries in memcached (with cachedump), the timestamp for expiration of an entry stays the same even after sleep.
Consider an example : After restart, an object is stored (at 1 AM UTC) with expiration of 1 hour from now
Computer time : 01:00:00 UTC
Memcached time : 01:00:00 UTC
Expiration timestamp : 1496109600 [02:00:00 UTC]
Computer sleeps for 30 minutes & resumes
Computer time : 01:30:00 UTC
Memcached time : 01:00:00 UTC -> drifts by 30 minutes
Expiration timestamp : 1496109600 [02:00:00 UTC] -> stays same
Expiration timestamp is still 2 AM UTC, but memcached's clock is 30 minutes behind the computer clock. As a result, the object would expire at 2:30 AM (as opposed to 2:00 AM, the intended time).
Is this a memcached bug or is my understanding incorrect ? I've experimented this by setting an actual object and I found that the expiration time drifts by the time the computer is put to sleep.
The text was updated successfully, but these errors were encountered:
That's intentional, unfortunately. Memcached implements a monotonic clock to ensure it always goes forward generally when time goes forward for the computer. When a computer is asleep time isn't going forward.
Without the monotonic clock NTP can jump time both forward and backwards; and if time goes backwards then forwards again you can create immortal objects with underflowed expiration times. Or if time goes forward then backward an object which was supposed to expire in 5 minutes could take hours or days (or years, if the clock is pretty screwed up on boot).