[master] c127b445c Add VCL_Shutdown to wait for VCL references to vanish
Nils Goroll
nils.goroll at uplex.de
Wed Aug 27 15:05:05 UTC 2025
commit c127b445c2b9dff9d90edc2cb8ab67a92daaf3d6
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Mar 7 20:55:28 2024 +0100
Add VCL_Shutdown to wait for VCL references to vanish
Before shutting down stevedores, we should wait for VCL references to go
away to, indirectly, ensure that all worker threads potentially using
storage functions are done.
See https://gitlab.com/uplex/varnish/slash/-/issues/61
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 31b94829f..ec3ad199f 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -387,6 +387,20 @@ cli_quit(int sig)
WRONG("It's time for the big quit");
}
+/*=====================================================================
+ * XXX Generalize?
+ */
+
+static void
+bit_set(volatile uint8_t *p, unsigned no)
+{
+ uint8_t b;
+
+ p += (no >> 3);
+ b = (0x80 >> (no & 7));
+ *p |= b;
+}
+
/*=====================================================================
* Run the child process
*/
@@ -538,12 +552,15 @@ child_main(int sigmagic, size_t altstksz)
CLI_Run();
+ bit_set(cache_param->debug_bits, DBG_VCLREL);
+
if (shutdown_delay > 0)
VTIM_sleep(shutdown_delay);
VCA_Shutdown();
BAN_Shutdown();
EXP_Shutdown();
+ VCL_Shutdown();
STV_close();
printf("Child dies\n");
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 2892ef188..0efa22a29 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -502,6 +502,7 @@ struct vsb *VCL_Rel_CliCtx(struct vrt_ctx **);
void VCL_Panic(struct vsb *, const char *nm, const struct vcl *);
void VCL_Poll(void);
void VCL_Init(void);
+void VCL_Shutdown(void);
#define VCL_MET_MAC(l,u,t,b) \
void VCL_##l##_method(struct vcl *, struct worker *, struct req *, \
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 944834b29..aa81c95f2 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -1270,3 +1270,26 @@ VCL_Init(void)
Lck_New(&vcl_mtx, lck_vcl);
VSL_Setup(&vsl_cli, NULL, 0);
}
+
+void
+VCL_Shutdown(void)
+{
+ struct vcl *vcl;
+ unsigned c = 0;
+
+ while (1) {
+ Lck_Lock(&vcl_mtx);
+ VTAILQ_FOREACH(vcl, &vcl_head, list)
+ if (vcl->busy)
+ break;
+ Lck_Unlock(&vcl_mtx);
+ if (vcl == NULL)
+ return;
+ if (++c % 10 == 0) {
+ fprintf(stderr, "shutdown waiting for %u reference%s "
+ "on %s\n", vcl->busy, vcl->busy > 1 ? "s" : "",
+ vcl->loaded_name);
+ }
+ usleep(100 * 1000);
+ }
+}
More information about the varnish-commit
mailing list