Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VCL_Shutdown to wait for VCL references to vanish #4078

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions bin/varnishd/cache/cache_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,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
*/
Expand Down Expand Up @@ -452,12 +466,16 @@ 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();
STV_warn();
VCL_Shutdown();
STV_close();

printf("Child dies\n");
Expand Down
2 changes: 2 additions & 0 deletions bin/varnishd/cache/cache_varnishd.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,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 *, \
Expand Down Expand Up @@ -569,6 +570,7 @@ void V2D_Init(void);

/* stevedore.c */
void STV_open(void);
void STV_warn(void);
void STV_close(void);
const struct stevedore *STV_next(void);
int STV_BanInfoDrop(const uint8_t *ban, unsigned len);
Expand Down
22 changes: 22 additions & 0 deletions bin/varnishd/cache/cache_vcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,3 +1027,25 @@ 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 vcl %u\t%s\n",
vcl->busy, vcl->loaded_name);
}
usleep(100 * 1000);
}
}
23 changes: 16 additions & 7 deletions bin/varnishd/storage/stevedore.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,28 @@ STV_open(void)
AN(stv_h2_rxbuf);
}

void
STV_warn(void)
{
struct stevedore *stv;

ASSERT_CLI();
/* First send close warning */
STV_Foreach(stv)
if (stv->close != NULL)
stv->close(stv, 0);
}

void
STV_close(void)
{
struct stevedore *stv;
int i;

ASSERT_CLI();
for (i = 1; i >= 0; i--) {
/* First send close warning */
STV_Foreach(stv)
if (stv->close != NULL)
stv->close(stv, i);
}
/* First send close warning */
STV_Foreach(stv)
if (stv->close != NULL)
stv->close(stv, 1);
}

/*-------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions bin/varnishtest/tests/r01506.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ client c1 {
} -run

varnish v1 -expect sc_range_short == 0
server s1 -wait
1 change: 1 addition & 0 deletions bin/varnishtest/tests/r02035.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ client c1 {

barrier b1 sync
} -run
server s1 -wait