Skip to content

Commit

Permalink
Work around arguably wrong event order in Varnish-Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
nigoroll committed Jan 5, 2024
1 parent 79d9d67 commit 1faceae
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/tests/r00107.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
varnishtest "regression test issue #107 dom_release() from unref_domains"

feature cmd "getent hosts localhost www.localhost img.localhost"

server s1 {
rxreq
expect req.http.Host == localhost
txresp

rxreq
expect req.http.Host == www.localhost
txresp

rxreq
expect req.http.Host == www.localhost
txresp
} -start

varnish v1 -vcl+backend {
import ${vmod_dynamic};

sub vcl_init {
new d1 = dynamic.director(
port = "${s1_port}",
ttl = 1m,
domain_usage_timeout = 900ms);
}

sub vcl_recv {
set req.backend_hint = d1.backend(req.http.Host);
return (pass);
}

sub vcl_backend_error {
# the director may resolve ::1 first
return (retry);
}
} -start

client c1 {
txreq -hdr "Host: localhost"
rxresp
expect resp.status == 200
} -run

delay 1

varnish v1 -vcl {backend proforma none;}

varnish v1 -cliok "vcl.state vcl1 cold"
9 changes: 9 additions & 0 deletions src/vmod_dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,11 @@ dynamic_search(struct vmod_dynamic_director *obj, const char *addr,
* We need to keep our backends around until the last reference to a domain is
* lost, otherwise it would stop working
*/

// XXX workaround #107 / VC#4037
static void v_matchproto_(vdi_event_f)
dom_event(VCL_BACKEND dir, enum vcl_event_e ev);

static void v_matchproto_(vdi_release_f)
dom_release(VCL_BACKEND dir)
{
Expand All @@ -951,6 +956,10 @@ dom_release(VCL_BACKEND dir)
CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(dom, dir->priv, DYNAMIC_DOMAIN_MAGIC);

// XXX workaround #107 / VC#4037
if (dom->thread)
dom_event(dir, VCL_EVENT_COLD);

AZ(dom->thread);
assert(dom->status == DYNAMIC_ST_READY);

Expand Down

0 comments on commit 1faceae

Please sign in to comment.