Ensure the expiry thread does not deadlock the server

If, for some reason, an fcore lock could not get aquired, the
expiry thread would keep the server locked until that file was
available again.

Avoid this situation with a trivial trylock and retry.
parent 1763d2d8
......@@ -30,6 +30,8 @@
#include <pthread.h>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#include "vdef.h"
#include "vrt.h"
......@@ -41,6 +43,8 @@
#include "tus_file_exp.h"
#include "tus_file_exp_setup.h"
#define RETRY_SECONDS 10
struct tus_exp {
unsigned magic;
#define TUS_EXP_MAGIC 0x105e8900
......@@ -96,11 +100,24 @@ tus_exp_thread(void *p)
AZ(pthread_mutex_unlock(&e->mtx));
AN(fcore);
srv = fcore->server;
tus_server_lock(srv);
AZ(pthread_mutex_lock(&fcore->mtx));
tus_file_del(&fcore);
tus_server_unlock(srv);
while (fcore != NULL) {
struct tus_file_core *has_lock = fcore;
tus_server_lock(srv);
(void) tus_file_trylock(&has_lock);
if (has_lock != NULL)
tus_file_del(&fcore);
tus_server_unlock(srv);
if (has_lock == NULL) {
fprintf(stderr, "tus expiry: fcore %p locked\n",
fcore);
sleep(RETRY_SECONDS);
}
}
AZ(pthread_mutex_lock(&e->mtx));
}
......
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