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

Commit 7a78d69

Browse files
committed
SQUASHME: Stash stale_oc available during vcl_miss also
While VCL has no access to the stale_oc during vcl_miss, a vmod could reference strings from it, so we also need to stash it until the end of the transaction. This roughly doubles the number of pointers we need to keep around, but the amount of additional memory on the workspace is still manageable. For the default max_restarts = 4, it is 80 bytes on 64bit.
1 parent aab6e31 commit 7a78d69

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

bin/varnishd/cache/cache_req.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ ocstash_clear(struct worker *wrk, struct ocstash *stash)
8484
}
8585

8686
void
87-
Req_StashObjcore(struct req *req)
87+
Req_StashObjcore(struct req *req, struct objcore **ocp)
8888
{
8989

9090
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
91-
ocstash_push(req->stash, &req->objcore);
91+
ocstash_push(req->stash, ocp);
9292
}
9393

9494
/*--------------------------------------------------------------------*/
@@ -241,7 +241,8 @@ Req_New(struct sess *sp, const struct req *preq)
241241

242242
req->max_restarts = cache_param->max_restarts;
243243
assert(req->max_restarts + 1 <= UINT16_MAX);
244-
l = req->max_restarts + 1;
244+
// each restart may ref one stale_oc and one oc
245+
l = (2 * req->max_restarts) + 1;
245246
sz = SIZEOF_FLEX_OBJ(req->stash, ocs, l);
246247
req->stash = (void*)p;
247248
req->stash->magic = OCSTASH_MAGIC;

bin/varnishd/cache/cache_req_fsm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
240240

241241
if (wrk->vpi->handling != VCL_RET_DELIVER) {
242242
HSH_Cancel(wrk, req->objcore, NULL);
243-
Req_StashObjcore(req);
243+
Req_StashObjcore(req, &req->objcore);
244244
http_Teardown(req->resp);
245245

246246
switch (wrk->vpi->handling) {
@@ -684,7 +684,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
684684
WRONG("Illegal return from vcl_hit{}");
685685
}
686686

687-
Req_StashObjcore(req);
687+
Req_StashObjcore(req, &req->objcore);
688688

689689
if (busy != NULL) {
690690
(void)HSH_DerefObjCore(wrk, &busy, 0);
@@ -714,7 +714,7 @@ cnt_miss(struct worker *wrk, struct req *req)
714714
wrk->stats->cache_miss++;
715715
VBF_Fetch(wrk, req, req->objcore, req->stale_oc, VBF_NORMAL);
716716
if (req->stale_oc != NULL)
717-
(void)HSH_DerefObjCore(wrk, &req->stale_oc, 0);
717+
Req_StashObjcore(req, &req->stale_oc);
718718
req->req_step = R_STP_FETCH;
719719
return (REQ_FSM_MORE);
720720
case VCL_RET_FAIL:
@@ -734,7 +734,7 @@ cnt_miss(struct worker *wrk, struct req *req)
734734
}
735735
VRY_Clear(req);
736736
if (req->stale_oc != NULL)
737-
(void)HSH_DerefObjCore(wrk, &req->stale_oc, 0);
737+
Req_StashObjcore(req, &req->stale_oc);
738738
AZ(HSH_DerefObjCore(wrk, &req->objcore, 1));
739739
return (REQ_FSM_MORE);
740740
}

bin/varnishd/cache/cache_varnishd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void Req_Fail(struct req *req, stream_close_t reason);
419419
void Req_AcctLogCharge(struct VSC_main_wrk *, struct req *);
420420
void Req_LogHit(struct worker *, struct req *, struct objcore *, intmax_t);
421421
const char *Req_LogStart(const struct worker *, struct req *);
422-
void Req_StashObjcore(struct req *);
422+
void Req_StashObjcore(struct req *, struct objcore **);
423423

424424
/* cache_req_body.c */
425425
int VRB_Ignore(struct req *);

bin/varnishtest/tests/r02219.vtc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ server s1 {
1111

1212
varnish v1 -arg "-p workspace_client=9k" \
1313
-arg "-p vsl_buffer=4k" \
14+
-arg "-p max_restarts=2" \
1415
-proto PROXY \
1516
-vcl+backend {
1617
import std;

include/tbl/params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ PARAM_SIMPLE(
786786
/* name */ max_restarts,
787787
/* type */ uint,
788788
/* min */ "0",
789-
/* max */ "65534", // (1<<16)-2 #4269
789+
/* max */ "32766", // (1<<15)-2 #4269
790790
/* def */ "4",
791791
/* units */ "restarts",
792792
/* descr */

0 commit comments

Comments
 (0)