X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=memcached%2Ftestapp.c;h=9faccf4e11cc2fe0e59600a31d82cb490ce2481a;hb=acdfe4229a70c323e66c37e2768dfdea42694bb1;hp=aba0b90519b78d9726be67ebaf1a1083ecae4bb8;hpb=81204a653b40f87ae9f43fd8ee12cc8177021f3a;p=m6w6%2Flibmemcached diff --git a/memcached/testapp.c b/memcached/testapp.c index aba0b905..9faccf4e 100644 --- a/memcached/testapp.c +++ b/memcached/testapp.c @@ -382,8 +382,8 @@ static pid_t start_server(in_port_t *port_out, bool daemon, int timeout) { if (daemon) { /* 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.... - */ + * finished writing the content, so we loop a few times + * reading as well */ while (access(pid_file, F_OK) == -1) { usleep(10); } @@ -394,7 +394,11 @@ static pid_t start_server(in_port_t *port_out, bool daemon, int timeout) { strerror(errno)); assert(false); } - assert(fgets(buffer, sizeof(buffer), fp) != NULL); + + /* Avoid race by retrying 20 times */ + for (int x = 0; x < 20 && fgets(buffer, sizeof(buffer), fp) == NULL; x++) { + usleep(10); + } fclose(fp); int32_t val;