diff options
author | Clint Byrum <clint@ubuntu.com> | 2012-07-27 02:27:14 -0700 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2012-07-27 02:27:14 -0700 |
commit | d707b99d92dbc7c36d08be223411f9fe26ed8bfc (patch) | |
tree | 975121995bdb3f9fb13934da81db48fa15a967b4 /testapp.c | |
parent | b19b41d968e064902dd585c68582b687e6ccdfc7 (diff) | |
download | memcached-d707b99d92dbc7c36d08be223411f9fe26ed8bfc.tar.gz |
Avoid race condition in test by re-trying
(ed note: yes it doesn't check for a NULL and die after 20 times. this should
mitigate until we can do better with writing the pidfile)
Diffstat (limited to 'testapp.c')
-rw-r--r-- | testapp.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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; |