Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Merge r4967: Fix a problem in director teardown at vcl.discard time
Browse files Browse the repository at this point in the history
We didn't create/destroy directors and backends in a consistent order,
and in some case we even destroyed directors more than once.

Always destroy in opposite order of creation (which follows VCL
source order).

Turn the bottom element of the array into (only) an indication
of which backend/director is the default.

Fixes:  #722



git-svn-id: http://www.varnish-cache.org/svn/branches/2.1@5040 d4fa192b-c00b-0410-8231-f00ffab90ce4
  • Loading branch information
Tollef Fog Heen committed Jul 13, 2010
1 parent fabdbeb commit ec9a6b0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
31 changes: 31 additions & 0 deletions bin/varnishtest/tests/r00722.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# $Id$

test "Director cleanup fails on vcl.discard"

server s1 {
rxreq
txresp
} -start

varnish v1 -vcl+backend {
director foo random {
{ .backend = s1; .weight = 1; }
{ .backend = { .host = "${s1_addr}"; .port = "${s1_port}";} .weight =1; }
{ .backend = { .host = "${s1_addr}"; .port = "${s1_port}";} .weight =1; }
}
sub vcl_recv {
set req.backend = foo;
}
} -start


varnish v1 -vcl+backend { }

varnish v1 -cliok "vcl.list"
varnish v1 -cliok "vcl.discard vcl1"

client c1 {
txreq
rxresp
} -run

24 changes: 19 additions & 5 deletions lib/libvcl/vcc_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm)

sprintf(vgcname, "%.*s_%d", PF(tl->t_dir), serial);

Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n",
PF(tl->t_dir));
vcc_ParseHostDef(tl, serial, vgcname);
if (tl->err) {
vsb_printf(tl->sb,
Expand Down Expand Up @@ -672,6 +670,7 @@ vcc_ParseDirector(struct tokenlist *tl)
{
struct token *t_first;
struct dirlist const *dl;
int isfirst;

t_first = tl->t;
vcc_NextToken(tl); /* ID: director | backend */
Expand All @@ -682,14 +681,12 @@ vcc_ParseDirector(struct tokenlist *tl)
vcc_NextToken(tl);


isfirst = tl->ndirector;
if (vcc_IdIs(t_first, "backend")) {
tl->t_policy = t_first;
vcc_ParseSimpleDirector(tl);
} else {
Fh(tl, 1, "\n#define VGC_backend__%.*s %d\n",
PF(tl->t_dir), tl->ndirector);
vcc_AddDef(tl, tl->t_dir, R_BACKEND);
tl->ndirector++;
ExpectErr(tl, ID); /* ID: policy */
tl->t_policy = tl->t;
vcc_NextToken(tl);
Expand All @@ -708,9 +705,14 @@ vcc_ParseDirector(struct tokenlist *tl)
dl->func(tl);
if (!tl->err)
SkipToken(tl, '}');
Fh(tl, 1, "\n#define VGC_backend__%.*s %d\n",
PF(tl->t_dir), tl->ndirector);
tl->ndirector++;
Fi(tl, 0,
"\tVRT_init_dir(cli, VCL_conf.director, \"%.*s\",\n",
PF(tl->t_policy));
Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n",
PF(tl->t_dir));
Fi(tl, 0, "\t VGC_backend__%.*s, &vgc_dir_priv_%.*s);\n",
PF(tl->t_dir), PF(tl->t_dir));

Expand All @@ -722,6 +724,18 @@ vcc_ParseDirector(struct tokenlist *tl)
vcc_ErrWhere(tl, t_first);
return;
}

if (isfirst == 1) {
/*
* If this is the first backend|director explicitly
* defined, use it as default backend.
*/
Fi(tl, 0,
"\tVCL_conf.director[0] = VCL_conf.director[%d];\n",
tl->ndirector - 1);
vcc_AddRef(tl, tl->t_dir, R_BACKEND);
}

tl->t_policy = NULL;
tl->t_dir = NULL;
}
3 changes: 2 additions & 1 deletion lib/libvcl/vcc_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ vcc_NewTokenList(void)
VTAILQ_INIT(&tl->sources);

tl->nsources = 0;
tl->ndirector = 1;

/* General C code */
tl->fc = vsb_newauto();
Expand Down Expand Up @@ -580,7 +581,7 @@ vcc_CompileSource(struct vsb *sb, struct source *sp)
return (vcc_DestroyTokenList(tl, NULL));

/* Check if we have any backends at all */
if (tl->ndirector == 0) {
if (tl->ndirector == 1) {
vsb_printf(tl->sb,
"No backends or directors found in VCL program, "
"at least one is necessary.\n");
Expand Down
4 changes: 0 additions & 4 deletions lib/libvcl/vcc_xref.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type)
}
r->defcnt++;
r->name = t;

/* The first backend is the default and thus has an implicit ref */
if (type == R_BACKEND && tl->ndirector == 0)
r->refcnt++;
}

/*--------------------------------------------------------------------*/
Expand Down

0 comments on commit ec9a6b0

Please sign in to comment.