Retry flock() 3 times with 100ms delay inbetween

It seems with the recent debian updates on my machine, some change
of timing/scheduling has come which makes flock() fail when the
lock holder is being killed by the timeout code in forkrun()

For future reference: logs/20231026_apt_history.txt
parent d2116ede
This diff is collapsed.
......@@ -5739,13 +5739,20 @@ fellow_log_init(const char *path, size_t wantsize, size_t objsz_hint,
path, strerror(errno), errno);
goto err_free;
}
if (flock(ffd->fd, LOCK_EX | LOCK_NB)) {
#define FLOCK_TRIES 3
for (i = 0; i < FLOCK_TRIES; i++) {
if (! flock(ffd->fd, LOCK_EX | LOCK_NB))
break;
assert(errno == EWOULDBLOCK);
ffd->diag("fellow: flock(%s) failed: %s (%d)"
" - a fellow file can only be used once\n",
path, strerror(errno), errno);
ffd->diag("fellow: %d/%d flock(%s) failed: %s (%d)\n",
i + 1, FLOCK_TRIES, path, strerror(errno), errno);
(void) usleep(100 * 1000); // 100ms
}
if (i == FLOCK_TRIES) {
ffd->diag("a fellow file can only be used once\n");
goto err_free;
}
#undef FLOCK_TRIES
ffd->cap = FFD_CAN_ANY;
memset(hdr, 0, sizeof hdr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment