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

Commit 6a108fd

Browse files
committed
vrt_var: Make req.ttl and req.grace unsetable
We continue to use a default value of -1 instead of changing the default to NAN. These variables can be read from VCL, and VCL does not want to deal with NAN.
1 parent 3378604 commit 6a108fd

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

bin/varnishd/cache/cache_vrt_var.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,24 @@ VRT_r_req_##nm(VRT_CTX) \
561561
return (ctx->req->elem); \
562562
}
563563

564+
#define REQ_VAR_U(nm, elem, val) \
565+
\
566+
VCL_VOID \
567+
VRT_u_req_##nm(VRT_CTX) \
568+
{ \
569+
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
570+
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
571+
ctx->req->elem = val; \
572+
}
573+
564574
REQ_VAR_R(backend_hint, director_hint, VCL_BACKEND)
565575

566576
REQ_VAR_L(ttl, d_ttl, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
567577
REQ_VAR_R(ttl, d_ttl, VCL_DURATION)
578+
REQ_VAR_U(ttl, d_ttl, -1)
568579
REQ_VAR_L(grace, d_grace, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
569580
REQ_VAR_R(grace, d_grace, VCL_DURATION)
581+
REQ_VAR_U(grace, d_grace, -1)
570582

571583
VCL_VOID
572584
VRT_l_req_backend_hint(VRT_CTX, VCL_BACKEND be)

bin/varnishtest/tests/b00084.vtc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
varnishtest "unset req.ttl and req.grace"
2+
3+
server s1 {
4+
rxreq
5+
expect req.http.ttl-initial == -1.000
6+
expect req.http.grace-initial == -1.000
7+
expect req.http.ttl-set == 0.000
8+
expect req.http.grace-set == 0.000
9+
expect req.http.ttl-unset == -1.000
10+
expect req.http.grace-unset == -1.000
11+
txresp
12+
} -start
13+
14+
varnish v1 -vcl+backend {
15+
sub vcl_recv {
16+
set req.http.ttl-initial = req.ttl;
17+
set req.http.grace-initial = req.grace;
18+
19+
set req.ttl = 0s;
20+
set req.grace = 0s;
21+
22+
set req.http.ttl-set = req.ttl;
23+
set req.http.grace-set = req.grace;
24+
25+
unset req.ttl;
26+
unset req.grace;
27+
28+
set req.http.ttl-unset = req.ttl;
29+
set req.http.grace-unset = req.grace;
30+
}
31+
} -start
32+
33+
client c1 -repeat 2 {
34+
txreq
35+
rxresp
36+
expect resp.status == 200
37+
} -run

doc/sphinx/reference/vcl_var.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,13 @@ req.grace
246246

247247
Writable from: client
248248

249+
Unsetable from: client
249250

250251
Upper limit on the object grace.
251252

252253
During lookup the minimum of req.grace and the object's stored
253-
grace value will be used as the object's grace.
254+
grace value will be used as the object's grace. Setting req.grace
255+
to 0s prevents hits on stale objects.
254256

255257

256258
.. _req.hash:
@@ -510,8 +512,10 @@ req.ttl
510512

511513
Writable from: client
512514

515+
Unsetable from: client
513516

514517
Upper limit on the object age for cache lookups to return hit.
518+
Lookups always miss when req.ttl is set to 0s.
515519

516520

517521
.. _req.url:

0 commit comments

Comments
 (0)