[master] 34b687e63 stop the expiry thread before closing stevedores
Nils Goroll
nils.goroll at uplex.de
Tue Jan 14 13:31:06 UTC 2020
commit 34b687e636d454eb03261552628b273c0ef58e45
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue Jan 14 14:25:35 2020 +0100
stop the expiry thread before closing stevedores
This should fix the panic mentioned in
309e807d3ff8810017451cb16c667d99125415aa
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 288c6a4d8..c55bfec91 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -52,9 +52,11 @@ struct exp_priv {
struct worker *wrk;
struct vsl_log vsl;
struct binheap *heap;
+ pthread_t thread;
};
static struct exp_priv *exphdl;
+static int exp_shutdown = 0;
/*--------------------------------------------------------------------
* Calculate an object's effective ttl time, taking req.ttl into account
@@ -332,7 +334,7 @@ exp_thread(struct worker *wrk, void *priv)
VSL_Setup(&ep->vsl, NULL, 0);
ep->heap = binheap_new(NULL, object_cmp, object_update);
AN(ep->heap);
- while (1) {
+ while (exp_shutdown == 0) {
Lck_Lock(&ep->mtx);
oc = VSTAILQ_FIRST(&ep->inbox);
@@ -361,7 +363,7 @@ exp_thread(struct worker *wrk, void *priv)
else
tnext = exp_expire(ep, t);
}
- NEEDLESS(return (NULL));
+ return (NULL);
}
/*--------------------------------------------------------------------*/
@@ -378,6 +380,26 @@ EXP_Init(void)
Lck_New(&ep->mtx, lck_exp);
AZ(pthread_cond_init(&ep->condvar, NULL));
VSTAILQ_INIT(&ep->inbox);
- exphdl = ep;
WRK_BgThread(&pt, "cache-exp", exp_thread, ep);
+ ep->thread = pt;
+ exphdl = ep;
+}
+
+void
+EXP_Shutdown(void)
+{
+ struct exp_priv *ep = exphdl;
+ void *status;
+
+ Lck_Lock(&ep->mtx);
+ exp_shutdown = 1;
+ AZ(pthread_cond_signal(&ep->condvar));
+ Lck_Unlock(&ep->mtx);
+
+ AN(ep->thread);
+ AZ(pthread_join(ep->thread, &status));
+ AZ(status);
+ memset(&ep->thread, 0, sizeof ep->thread);
+
+ /* XXX could cleanup more - not worth it for now */
}
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index e96794403..8e8e50664 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -229,6 +229,7 @@ extern const struct vdp VDP_range;
/* cache_expire.c */
void EXP_Init(void);
+void EXP_Shutdown(void);
/* cache_fetch.c */
enum vbf_fetch_mode_e {
More information about the varnish-commit
mailing list