Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit 6c1a673

Browse files
committed
Optimize lookup
Fix potential case when varnish stops responding with a large number of bans and variations
1 parent f279c0c commit 6c1a673

3 files changed

Lines changed: 93 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Makefile.in
66
_*
77
.deps/
88
.libs/
9+
.vscode/
910
*.o
1011
*.a
1112
*.lo

bin/varnishd/cache/cache_hash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,6 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
451451
if (oc->ttl <= 0.)
452452
continue;
453453

454-
if (BAN_CheckObject(wrk, oc, req)) {
455-
oc->flags |= OC_F_DYING;
456-
EXP_Remove(oc, NULL);
457-
continue;
458-
}
459-
460454
if (!req->hash_ignore_vary && ObjHasAttr(wrk, oc, OA_VARY)) {
461455
vary = ObjGetAttr(wrk, oc, OA_VARY, NULL);
462456
AN(vary);
@@ -466,6 +460,12 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
466460
}
467461
}
468462

463+
if (BAN_CheckObject(wrk, oc, req)) {
464+
oc->flags |= OC_F_DYING;
465+
EXP_Remove(oc, NULL);
466+
continue;
467+
}
468+
469469
if (req->vcf != NULL) {
470470
vr = req->vcf->func(req, &oc, &exp_oc, 0);
471471
if (vr == VCF_CONTINUE)

bin/varnishtest/tests/c00133.vtc

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
varnishtest "Optimized HSH_Lookup - ban is checked after Vary is matched"
2+
3+
server s1 {
4+
rxreq
5+
expect req.url == /foo
6+
expect req.http.foobar == "1"
7+
txresp -hdr "Vary: Foobar" -body "1111"
8+
9+
rxreq
10+
expect req.url == /foo
11+
expect req.http.foobar == "2"
12+
txresp -hdr "Vary: Foobar" -body "2222"
13+
14+
rxreq
15+
expect req.url == /foo
16+
expect req.http.foobar == "3"
17+
txresp -hdr "Vary: Foobar" -body "3333"
18+
19+
rxreq
20+
expect req.url == /foo
21+
expect req.http.foobar == "1"
22+
txresp -hdr "Vary: Foobar" -body "1111"
23+
24+
rxreq
25+
expect req.url == /foo
26+
expect req.http.foobar == "1"
27+
txresp -hdr "Vary: Foobar" -body "1111"
28+
29+
} -start
30+
31+
varnish v1 -vcl+backend {
32+
sub vcl_backend_response {
33+
set beresp.http.url = bereq.url;
34+
}
35+
} -start
36+
37+
38+
client c1 {
39+
txreq -url /foo -hdr "Foobar: 1"
40+
rxresp
41+
expect resp.body == "1111"
42+
} -run
43+
44+
client c1 {
45+
txreq -url /foo -hdr "Foobar: 2"
46+
rxresp
47+
expect resp.body == "2222"
48+
} -run
49+
50+
client c1 {
51+
txreq -url /foo -hdr "Foobar: 3"
52+
rxresp
53+
expect resp.body == "3333"
54+
55+
} -run
56+
57+
varnish v1 -expect n_object == 3
58+
varnish v1 -expect cache_hit == 0
59+
varnish v1 -expect cache_miss == 3
60+
61+
client c1 {
62+
txreq -url /foo -hdr "Foobar: 1"
63+
rxresp
64+
} -run
65+
66+
varnish v1 -expect cache_hit == 1
67+
varnish v1 -expect cache_miss == 3
68+
69+
varnish v1 -cliok "ban obj.http.url == /foo"
70+
varnish v1 -cliok "ban obj.http.url == /bar"
71+
varnish v1 -cliok "ban obj.http.url == /baz"
72+
73+
client c1 {
74+
txreq -url /foo -hdr "Foobar: 1"
75+
rxresp
76+
} -run
77+
78+
varnish v1 -expect bans_tested == 1
79+
varnish v1 -expect bans_tests_tested == 3
80+
varnish v1 -expect bans_obj_killed == 1
81+
varnish v1 -expect n_object == 3
82+
83+
84+
varnish v1 -expect cache_hit == 1
85+
varnish v1 -expect cache_miss == 4
86+
varnish v1 -expect client_req == 5

0 commit comments

Comments
 (0)