allen8807 / memcached

Automatically exported from code.google.com/p/memcached
0 stars 0 forks source link

testapp.c sometimes fails due to race condition #252

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. build memcached, run 'make check' and then ./testapp
2. Repeat many many times. Seems to fail more often on linux ppc64 and os x

Alternatively apply this patch to create an artificial race:

diff --git a/memcached.c b/memcached.c
index b121e16..678690b 100644
--- a/memcached.c
+++ b/memcached.c
@@ -4604,6 +4604,8 @@ static void save_pid(const char *pid_file) {
         return;
     }

+    usleep(25);
+
     fprintf(fp,"%ld\n", (long)getpid());
     if (fclose(fp) == -1) {
         vperror("Could not close the pid file %s", pid_file);

Error will be something like:

testapp: testapp.c:397: start_server: Assertion `fgets(buffer, sizeof(buffer), 
fp) != ((void *)0)' failed.

What version of the product are you using? On what operating system?

Have seen this on 1.4.13, and trunk, on Ubuntu.

Note that there is even a comment in this test that acknowledges the problem:

        /* loop and wait for the pid file.. There is a potential race
         * condition that the server just created the file but isn't
         * finished writing the content, but I'll take the chance....
         */

The attached patch solves the issue by retrying 5 times with 10us sleeps in 
between.

Original issue reported on code.google.com by superama...@gmail.com on 11 Feb 2012 at 8:36

Attachments:

GoogleCodeExporter commented 9 years ago
Discussed with Clint on irc - this is the patch we are using for the official 
Ubuntu 12.04 memcached package.

Original comment by ringo.p...@gmail.com on 4 Apr 2012 at 4:44

Attachments:

GoogleCodeExporter commented 9 years ago
Should've had a failsafe at the end to still assert on NULL but that's pedantic.

should hopefully have the daemonization process made more robust in the next 
few cuts and it won't matter. thanks!

Original comment by dorma...@rydia.net on 27 Jul 2012 at 9:29