This repository was archived by the owner on Feb 16, 2026. It is now read-only.
Commit 000c62d
committed
cache_req_fsm: Keep object cores referenced during the task
Context:
Only while we hold a reference to an object are we allowed to access any
attributes from it. With restarts, we might want to keep references to
attributes of objects from previous restart iterations. Before this patch, this
could lead to use-after-dereference, which was "fixed" by always copying object
variables into the request's workspace.
But that is wasteful, so we should rather make sure that we keep references
until we are done with the task and not copy (which is the next commit).
An argument had been made in the past that keeping object references until the
end of the task would increase their lifetime by too much, but restarts in VCL
really should be done within milliseconds in most cases - and if keeping
references _is_ an actual problem in specific situations, those can be avoided
by either not restarting or rolling back also. In general, until now we have
charged all Varnish-Cache users with the cost for specific use cases, but we
should rather only charge the specific use cases instead.
Implementation:
stash_oc() allocates basically a Variable Length Array (VLA) on the workspace
with a fallback to heap. The fallback exists to not complicate the calling code
with additional error handling.
For each invocation, stash_oc() copies the passed objcore to one of max_restarts
+ 1 slots and clears the original location as HSH_DerefObjCore() would.
Alternatives considered:
* Dynamically allocating space for each objcore pointer was dismissed due to the
substantial overhead.
* Using a TASK_PRIV was tried and dismissed because this would require setting
up a VRT_CTX or pulling the VRT_CTX out one level to the core of the FSM,
which was intrusive and increased complexity substantially.1 parent 5936324 commit 000c62d
3 files changed
Lines changed: 73 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| |||
548 | 549 | | |
549 | 550 | | |
550 | 551 | | |
| 552 | + | |
| 553 | + | |
551 | 554 | | |
552 | 555 | | |
553 | 556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
81 | 145 | | |
82 | 146 | | |
83 | 147 | | |
| |||
240 | 304 | | |
241 | 305 | | |
242 | 306 | | |
243 | | - | |
| 307 | + | |
244 | 308 | | |
245 | 309 | | |
246 | 310 | | |
| |||
286 | 350 | | |
287 | 351 | | |
288 | 352 | | |
| 353 | + | |
| 354 | + | |
289 | 355 | | |
290 | 356 | | |
291 | 357 | | |
| |||
557 | 623 | | |
558 | 624 | | |
559 | 625 | | |
| 626 | + | |
560 | 627 | | |
561 | 628 | | |
562 | 629 | | |
| |||
1213 | 1280 | | |
1214 | 1281 | | |
1215 | 1282 | | |
| 1283 | + | |
1216 | 1284 | | |
1217 | 1285 | | |
1218 | 1286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| |||
0 commit comments