Skip to content

Commit afb0ca1

Browse files
committed
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
1 parent 1db36d3 commit afb0ca1

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

bin/varnishd/cache/cache_main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,20 @@ cli_quit(int sig)
385385
WRONG("It's time for the big quit");
386386
}
387387

388+
/*=====================================================================
389+
* XXX Generalize?
390+
*/
391+
392+
static void
393+
bit_set(volatile uint8_t *p, unsigned no)
394+
{
395+
uint8_t b;
396+
397+
p += (no >> 3);
398+
b = (0x80 >> (no & 7));
399+
*p |= b;
400+
}
401+
388402
/*=====================================================================
389403
* Run the child process
390404
*/
@@ -490,12 +504,15 @@ child_main(int sigmagic, size_t altstksz)
490504

491505
CLI_Run();
492506

507+
bit_set(cache_param->debug_bits, DBG_VCLREL);
508+
493509
if (shutdown_delay > 0)
494510
VTIM_sleep(shutdown_delay);
495511

496512
VCA_Shutdown();
497513
BAN_Shutdown();
498514
EXP_Shutdown();
515+
VCL_Shutdown();
499516
STV_close();
500517

501518
printf("Child dies\n");

bin/varnishd/cache/cache_varnishd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ struct vsb *VCL_Rel_CliCtx(struct vrt_ctx **);
493493
void VCL_Panic(struct vsb *, const char *nm, const struct vcl *);
494494
void VCL_Poll(void);
495495
void VCL_Init(void);
496+
void VCL_Shutdown(void);
496497

497498
#define VCL_MET_MAC(l,u,t,b) \
498499
void VCL_##l##_method(struct vcl *, struct worker *, struct req *, \

bin/varnishd/cache/cache_vcl.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,3 +1180,25 @@ VCL_Init(void)
11801180
Lck_New(&vcl_mtx, lck_vcl);
11811181
VSL_Setup(&vsl_cli, NULL, 0);
11821182
}
1183+
1184+
void
1185+
VCL_Shutdown(void)
1186+
{
1187+
struct vcl *vcl;
1188+
unsigned c = 0;
1189+
1190+
while (1) {
1191+
Lck_Lock(&vcl_mtx);
1192+
VTAILQ_FOREACH(vcl, &vcl_head, list)
1193+
if (vcl->busy)
1194+
break;
1195+
Lck_Unlock(&vcl_mtx);
1196+
if (vcl == NULL)
1197+
return;
1198+
if (++c % 10 == 0) {
1199+
fprintf(stderr, "shutdown waiting for vcl %u\t%s\n",
1200+
vcl->busy, vcl->loaded_name);
1201+
}
1202+
usleep(100 * 1000);
1203+
}
1204+
}

0 commit comments

Comments
 (0)