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

Commit 6ad7be6

Browse files
committed
vcl_vrt: Skip VCL execution if the client is gone
Once a client is reportedly gone, processing its VCL task(s) is just a waste of resources. The execution of client-facing VCL is intercepted and an artificial return(fail) is returned in that scenario. Thanks to the introduction of the universal return(fail) proper error handling and resource tear down is already in place, which makes this change safe modulus unknown bugs. This adds a circuit breaker anywhere in the client state machine where there is VCL execution. A new Reset time stamp is logged to convey when a task does not complete because the client is gone. This is a good complement to the walk away feature and its original circuit breaker for the waiting list, but this has not been integrated yet. While the request is technically failed, it won't increase the vcl_fail counter, and a new req_reset counter is incremented. This new behavior is guarded by a new vcl_req_reset feature flag, enabled by default. Refs #3835 Refs 61a15cb Refs e5efc2c Refs ba54dc9 Refs 6f50a00 Refs b881699
1 parent ff8ae1f commit 6ad7be6

6 files changed

Lines changed: 57 additions & 1 deletion

File tree

bin/varnishd/cache/cache_vrt_vcl.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "vbm.h"
4343

4444
#include "cache_director.h"
45+
#include "cache_transport.h"
4546
#include "cache_vcl.h"
4647
#include "vcc_interface.h"
4748

@@ -521,6 +522,40 @@ VRT_VCL_Allow_Discard(struct vclref **refp)
521522
FREE_OBJ(ref);
522523
}
523524

525+
/*--------------------------------------------------------------------
526+
*/
527+
528+
static int
529+
req_poll(struct worker *wrk, struct req *req)
530+
{
531+
struct req *top;
532+
533+
/* NB: Since a fail transition leads to vcl_synth, the request may be
534+
* short-circuited twice.
535+
*/
536+
if (req->req_reset) {
537+
wrk->vpi->handling = VCL_RET_FAIL;
538+
return (-1);
539+
}
540+
541+
top = req->top->topreq;
542+
CHECK_OBJ_NOTNULL(top, REQ_MAGIC);
543+
CHECK_OBJ_NOTNULL(top->transport, TRANSPORT_MAGIC);
544+
545+
if (!FEATURE(FEATURE_VCL_REQ_RESET))
546+
return (0);
547+
if (top->transport->poll == NULL)
548+
return (0);
549+
if (top->transport->poll(top) >= 0)
550+
return (0);
551+
552+
VSLb_ts_req(req, "Reset", W_TIM_real(wrk));
553+
wrk->stats->req_reset++;
554+
wrk->vpi->handling = VCL_RET_FAIL;
555+
req->req_reset = 1;
556+
return (-1);
557+
}
558+
524559
/*--------------------------------------------------------------------
525560
* Method functions to call into VCL programs.
526561
*
@@ -552,6 +587,8 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
552587
CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
553588
CHECK_OBJ_NOTNULL(req->vcl, VCL_MAGIC);
554589
CHECK_OBJ_NOTNULL(req->top, REQTOP_MAGIC);
590+
if (req_poll(wrk, req))
591+
return;
555592
VCL_Req2Ctx(&ctx, req);
556593
}
557594
assert(ctx.now != 0);

doc/sphinx/reference/vsl.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ Resp
7676
Restart
7777
Client request is being restarted.
7878

79+
Reset
80+
The client closed its connection or reset its stream. Request
81+
processing is interrupted and considered failed.
82+
7983
Pipe handling timestamps
8084
~~~~~~~~~~~~~~~~~~~~~~~~
8185

include/tbl/feature_bits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ FEATURE_BIT(TRACE, trace,
9191
"Required for tracing vcl_init / vcl_fini"
9292
)
9393

94+
FEATURE_BIT(VCL_REQ_RESET, vcl_req_reset,
95+
"Stop processing client VCL once the client is gone. "
96+
"When this happens MAIN.req_reset is incremented."
97+
)
98+
9499
#undef FEATURE_BIT
95100

96101
/*lint -restore */

include/tbl/params.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,9 @@ PARAM_PRE
18241824
PARAM_BITS(
18251825
/* name */ feature,
18261826
/* fld */ feature_bits,
1827-
/* def */ "+validate_headers",
1827+
/* def */
1828+
"+validate_headers,"
1829+
"+vcl_req_reset",
18281830
/* descr */
18291831
"Enable/Disable various minor features.\n"
18301832
"\tdefault\tSet default value\n"

include/tbl/req_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ REQ_FLAG(is_hit, 0, 0, "")
4040
REQ_FLAG(waitinglist, 0, 0, "")
4141
REQ_FLAG(want100cont, 0, 0, "")
4242
REQ_FLAG(late100cont, 0, 0, "")
43+
REQ_FLAG(req_reset, 0, 0, "")
4344
#define REQ_BEREQ_FLAG(lower, vcl_r, vcl_w, doc) \
4445
REQ_FLAG(lower, vcl_r, vcl_w, doc)
4546
#include "tbl/req_bereq_flags.h"

lib/libvsc/VSC_main.vsc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@
345345
Number of times an HTTP/2 stream was refused because the queue was
346346
too long already. See also parameter thread_queue_limit.
347347

348+
.. varnish_vsc:: req_reset
349+
:group: wrk
350+
:oneliner: Requests reset
351+
352+
Number of times a client left before the VCL processing of its
353+
requests completed.
354+
348355
.. varnish_vsc:: n_object
349356
:type: gauge
350357
:group: wrk

0 commit comments

Comments
 (0)