[PATCH 1/2] Remove negative Age assertion and truncate to zero instead.
Martin Blix Grydeland
martin at varnish-software.com
Fri Apr 25 11:35:41 CEST 2014
The Age reported on response objects is calculated from the last
request timestamp taken. For a cache hit that hasn't been on a
waitinglist, that will be the Start timestamp. This opens a race where
the requests' last timestamp could be before the objects t_origin.
Truncate the Age to zero rather than assert in that case.
bin/varnishd/cache/cache_req_fsm.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 2518422..af5d76b 100644
@@ -117,10 +117,15 @@ cnt_deliver(struct worker *wrk, struct req *req)
/* We base Age calculation upon the last timestamp taken during
client request processing. This gives some inaccuracy, but
since Age is only full second resolution that shouldn't
- matter. */
- assert(req->t_prev > req->obj->exp.t_origin);
- http_PrintfHeader(req->resp, "Age: %.0f",
- req->t_prev - req->obj->exp.t_origin);
+ matter. (Last request timestamp could be a Start timestamp
+ taken before the object entered into cache leading to negative
+ age. Truncate to zero in that case).
+ if (req->t_prev > req->obj->exp.t_origin)
+ http_PrintfHeader(req->resp, "Age: %.0f",
+ req->t_prev - req->obj->exp.t_origin);
+ http_PrintfHeader(req->resp, "Age: %.0f", 0.);
http_SetHeader(req->resp, "Via: 1.1 varnish (v4)");
More information about the varnish-dev