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

Commit 671b93b

Browse files
dridinigoroll
authored andcommitted
condfetch: Test retrying a bereq on a dying stale object
The built-in vcl_refresh_valid returns a 503 error if the stale object used for revalidation gets invalidated while the backend fetch is in progress. One alternative is to not dismiss the stale object, but that can lead to invalidated objects being re-instantiated through concurrent refreshes (#4082). This test case covers the other alternative, which is to retry the fetch. We could use sub vcl_refresh_valid { if (!obj_stale.is_valid) { # core code removes conditional headers INM/IMS return (retry); } } but more realisticly, real world VCL will retry in v_b_e, so we take that route and keep the built-in vcl_refresh_valid {} The plain retry works because core code detects the invalidated stale object and removes the conditional headers. Committer edit: Removed code change from original commit, edited test case and, rewrote commit message. See #4400 (comment)
1 parent 8802338 commit 671b93b

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

bin/varnishtest/tests/c00129.vtc

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
varnishtest "304 on invalidated stale object"
2+
3+
barrier b1 cond 2
4+
barrier b2 cond 2
5+
6+
server s1 {
7+
rxreq
8+
txresp -hdr {ETag: "foo"} -body corrupted
9+
10+
rxreq
11+
expect req.http.If-None-Match == {"foo"}
12+
barrier b1 sync
13+
barrier b2 sync
14+
txresp -status 304 -hdr {ETag: "foo"}
15+
16+
close
17+
accept
18+
19+
rxreq
20+
expect req.http.If-None-Match == <undef>
21+
txresp -hdr {ETag: "foo"} -body valid
22+
} -start
23+
24+
varnish v1 -vcl+backend {
25+
sub vcl_recv {
26+
if (req.method == "PURGE") {
27+
return (purge);
28+
}
29+
}
30+
sub vcl_backend_response {
31+
set beresp.ttl = 1ms;
32+
set beresp.grace = 0s;
33+
set beresp.keep = 10s;
34+
}
35+
# rather than modifying vcl_refresh_valid, we retry in v_b_e, which is
36+
# more generic and likely to be found in real-world configs.
37+
sub vcl_backend_error {
38+
if (bereq.retries == 0) {
39+
return (retry);
40+
}
41+
}
42+
sub vcl_deliver {
43+
set resp.http.obj-hits = obj.hits;
44+
}
45+
} -start
46+
47+
client c1 {
48+
txreq
49+
rxresp
50+
expect resp.body == corrupted
51+
expect resp.http.obj-hits == 0
52+
53+
delay 0.1
54+
55+
txreq
56+
rxresp
57+
expect resp.body == valid
58+
expect resp.http.obj-hits == 0
59+
} -start
60+
61+
barrier b1 sync
62+
client c2 {
63+
txreq -req PURGE
64+
rxresp
65+
} -run
66+
barrier b2 sync
67+
68+
client c1 -wait

0 commit comments

Comments
 (0)