[memcached] bradfitz, r456: 2006-12-23

commits at code.sixapart.com commits at code.sixapart.com
Sun Dec 24 20:17:09 UTC 2006


2006-12-23
        * fix expirations of items set with absolute expiration times in
          the past, before the server's start time.  bug was introduced in
          1.2.0 with rel_time_t.  Thanks to Adam Dixon
          <adamtdixon at gmail.com> for the bug report and test case!




U   trunk/server/ChangeLog
U   trunk/server/memcached.c
U   trunk/server/t/expirations.t


Modified: trunk/server/ChangeLog
===================================================================
--- trunk/server/ChangeLog	2006-12-05 10:39:31 UTC (rev 455)
+++ trunk/server/ChangeLog	2006-12-24 20:17:08 UTC (rev 456)
@@ -1,3 +1,9 @@
+2006-12-23
+	* fix expirations of items set with absolute expiration times in
+	  the past, before the server's start time.  bug was introduced in
+	  1.2.0 with rel_time_t.  Thanks to Adam Dixon
+	  <adamtdixon at gmail.com> for the bug report and test case!
+
 2006-11-26
 	* Steven Grimm <sgrimm at facebook.com>: Performance improvements:
 	  

Modified: trunk/server/memcached.c
===================================================================
--- trunk/server/memcached.c	2006-12-05 10:39:31 UTC (rev 455)
+++ trunk/server/memcached.c	2006-12-24 20:17:08 UTC (rev 456)
@@ -87,9 +87,17 @@
 
     if (exptime == 0) return 0; /* 0 means never expire */
 
-    if (exptime > REALTIME_MAXDELTA)
+    if (exptime > REALTIME_MAXDELTA) {
+        /* if item expiration is at/before the server started, give it an
+           expiration time of 1 second after the server started.
+           (because 0 means don't expire).  without this, we'd
+           underflow and wrap around to some large value way in the
+           future, effectively making items expiring in the past
+           really expiring never */
+        if (exptime <= stats.started)
+            return (rel_time_t) 1;
         return (rel_time_t) (exptime - stats.started);
-    else {
+    } else {
         return (rel_time_t) (exptime + current_time);
     }
 }

Modified: trunk/server/t/expirations.t
===================================================================
--- trunk/server/t/expirations.t	2006-12-05 10:39:31 UTC (rev 455)
+++ trunk/server/t/expirations.t	2006-12-24 20:17:08 UTC (rev 456)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 
 use strict;
-use Test::More tests => 8;
+use Test::More tests => 10;
 use FindBin qw($Bin);
 use lib "$Bin/lib";
 use MemcachedTest;
@@ -47,3 +47,8 @@
 sleep(2.2);
 mem_get_is($sock, "foo", undef, "now expired");
 
+$expire = time() - 20;
+print $sock "set boo 0 $expire 6\r\nbooval\r\n";
+is(scalar <$sock>, "STORED\r\n", "stored boo");
+mem_get_is($sock, "boo", undef, "now expired");
+




More information about the memcached-commits mailing list