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

Commit b433ea1

Browse files
committed
vrt_var: req.ttl and req.grace is NAN when not set
Since VCL is not prepared to deal with NAN, the accessor function converts NAN to 0. As a side effect, we are no longer able to determine whether req.ttl and req.grace are set.
1 parent 590ff9f commit b433ea1

5 files changed

Lines changed: 20 additions & 17 deletions

File tree

bin/varnishd/cache/cache_expire.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ EXP_Ttl(const struct req *req, const struct objcore *oc)
7373
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
7474

7575
r = oc->ttl;
76-
if (req != NULL && req->d_ttl >= 0. && req->d_ttl < r)
76+
if (req != NULL && !isnan(req->d_ttl) && req->d_ttl < r)
7777
r = req->d_ttl;
7878
return (oc->t_origin + r);
7979
}
@@ -91,7 +91,7 @@ EXP_Ttl_grace(const struct req *req, const struct objcore *oc)
9191
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
9292

9393
g = oc->grace;
94-
if (req != NULL && req->d_grace >= 0. && req->d_grace < g)
94+
if (req != NULL && !isnan(req->d_grace) && req->d_grace < g)
9595
g = req->d_grace;
9696
return (EXP_Ttl(req, oc) + g);
9797
}

bin/varnishd/cache/cache_req_fsm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ cnt_recv_prep(struct req *req, const char *ci)
891891
VRT_Assign_Backend(&req->director_hint,
892892
VCL_DefaultDirector(req->vcl));
893893

894-
req->d_ttl = -1;
895-
req->d_grace = -1;
894+
req->d_ttl = NAN;
895+
req->d_grace = NAN;
896896
req->disable_esi = 0;
897897
req->hash_always_miss = 0;
898898
req->hash_ignore_busy = 0;

bin/varnishd/cache/cache_vrt_var.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,17 @@ VRT_l_req_##nm(VRT_CTX, type arg) \
566566
ctx->req->elem = arg; \
567567
}
568568

569-
#define REQ_VAR_R(nm, elem, type) \
569+
#define REQ_VAR_R(nm, elem, type, extra) \
570570
\
571571
type \
572572
VRT_r_req_##nm(VRT_CTX) \
573573
{ \
574+
type e; \
574575
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
575576
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
576-
return (ctx->req->elem); \
577+
e = ctx->req->elem; \
578+
extra; \
579+
return (e); \
577580
}
578581

579582
#define REQ_VAR_U(nm, elem, val) \
@@ -586,14 +589,14 @@ VRT_u_req_##nm(VRT_CTX) \
586589
ctx->req->elem = val; \
587590
}
588591

589-
REQ_VAR_R(backend_hint, director_hint, VCL_BACKEND)
592+
REQ_VAR_R(backend_hint, director_hint, VCL_BACKEND, )
590593

591594
REQ_VAR_L(ttl, d_ttl, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
592-
REQ_VAR_R(ttl, d_ttl, VCL_DURATION)
593-
REQ_VAR_U(ttl, d_ttl, -1)
595+
REQ_VAR_R(ttl, d_ttl, VCL_DURATION, if (isnan(e)) e = 0;)
596+
REQ_VAR_U(ttl, d_ttl, NAN)
594597
REQ_VAR_L(grace, d_grace, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
595-
REQ_VAR_R(grace, d_grace, VCL_DURATION)
596-
REQ_VAR_U(grace, d_grace, -1)
598+
REQ_VAR_R(grace, d_grace, VCL_DURATION, if (isnan(e)) e = 0;)
599+
REQ_VAR_U(grace, d_grace, NAN)
597600

598601
VCL_VOID
599602
VRT_l_req_backend_hint(VRT_CTX, VCL_BACKEND be)

bin/varnishtest/tests/b00064.vtc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ client c2 {
8484
expect resp.status == 200
8585
expect resp.body == "1"
8686
expect resp.http.X-grace == "60.000"
87-
expect resp.http.X-req-grace < 0.
87+
expect resp.http.X-req-grace == "0.000"
8888
expect resp.http.X-was-bgfetch == <undef>
8989
} -run
9090

@@ -118,7 +118,7 @@ client c4 {
118118
# We should get what c1 got in the very beginning
119119
expect resp.body == "1"
120120
expect resp.http.X-grace == "60.000"
121-
expect resp.http.X-req-grace < 0.
121+
expect resp.http.X-req-grace == "0.000"
122122
expect resp.http.X-was-bgfetch == <undef>
123123
} -start
124124

bin/varnishtest/tests/b00086.vtc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ varnishtest "unset req.ttl and req.grace"
22

33
server s1 {
44
rxreq
5-
expect req.http.ttl-initial == -1.000
6-
expect req.http.grace-initial == -1.000
5+
expect req.http.ttl-initial == 0.000
6+
expect req.http.grace-initial == 0.000
77
expect req.http.ttl-set == 0.000
88
expect req.http.grace-set == 0.000
9-
expect req.http.ttl-unset == -1.000
10-
expect req.http.grace-unset == -1.000
9+
expect req.http.ttl-unset == 0.000
10+
expect req.http.grace-unset == 0.000
1111
txresp
1212
} -start
1313

0 commit comments

Comments
 (0)