Skip to content

Commit fa83fee

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 varnishcache#3835 Refs 61a15cb Refs e5efc2c Refs ba54dc9 Refs 6f50a00 Refs b881699 Conflicts: include/tbl/feature_bits.h
1 parent 467a4db commit fa83fee

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
@@ -86,6 +86,11 @@ FEATURE_BIT(BUSY_STATS_RATE, busy_stats_rate,
8686
"Make busy workers comply with thread_stats_rate."
8787
)
8888

89+
FEATURE_BIT(VCL_REQ_RESET, vcl_req_reset,
90+
"Stop processing client VCL once the client is gone. "
91+
"When this happens MAIN.req_reset is incremented."
92+
)
93+
8994
#undef FEATURE_BIT
9095

9196
/*lint -restore */

include/tbl/params.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,9 @@ PARAM_PRE
18101810
PARAM_BITS(
18111811
/* name */ feature,
18121812
/* fld */ feature_bits,
1813-
/* def */ "+validate_headers",
1813+
/* def */
1814+
"+validate_headers,"
1815+
"+vcl_req_reset",
18141816
/* descr */
18151817
"Enable/Disable various minor features.\n"
18161818
"\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
@@ -342,6 +342,13 @@
342342
Number of times an HTTP/2 stream was refused because the queue was
343343
too long already. See also parameter thread_queue_limit.
344344

345+
.. varnish_vsc:: req_reset
346+
:group: wrk
347+
:oneliner: Requests reset
348+
349+
Number of times a client left before the VCL processing of its
350+
requests completed.
351+
345352
.. varnish_vsc:: n_object
346353
:type: gauge
347354
:group: wrk

0 commit comments

Comments
 (0)