Skip to content

Commit 6ecc9ec

Browse files
committed
http2_session: Implement transport polling
The error check is not performed in a critical section to avoid contention, at the risk of not seeing the error until the next transport poll.
1 parent 2c5b14a commit 6ecc9ec

5 files changed

Lines changed: 94 additions & 4 deletions

File tree

bin/varnishd/http2/cache_http2_session.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,16 @@ h2_new_session(struct worker *wrk, void *arg)
441441
wrk->vsl = NULL;
442442
}
443443

444+
static int v_matchproto_(vtr_poll_f)
445+
h2_poll(struct req *req)
446+
{
447+
struct h2_req *r2;
448+
449+
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
450+
CAST_OBJ_NOTNULL(r2, req->transport_priv, H2_REQ_MAGIC);
451+
return (r2->error ? -1 : 1);
452+
}
453+
444454
struct transport HTTP2_transport = {
445455
.name = "HTTP/2",
446456
.magic = TRANSPORT_MAGIC,
@@ -450,4 +460,5 @@ struct transport HTTP2_transport = {
450460
.req_body = h2_req_body,
451461
.req_fail = h2_req_fail,
452462
.sess_panic = h2_sess_panic,
463+
.poll = h2_poll,
453464
};

bin/varnishtest/tests/t02014.vtc

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ barrier b2 sock 3
55
barrier b3 sock 3
66
barrier b4 sock 3
77

8+
barrier b2_err cond 2
9+
barrier b3_err cond 2
10+
811
server s1 {
912
rxreq
1013
txresp -bodylen 66300
@@ -64,21 +67,39 @@ client c1 {
6467
stream 0 -wait
6568
} -run
6669

70+
varnish v1 -vsl_catchup
71+
72+
logexpect l2 -v v1 -g raw {
73+
expect * * ReqMethod GET
74+
expect * = VCL_call DELIVER
75+
} -start
76+
6777
client c2 {
6878
stream 0 {
6979
barrier b2 sync
7080
} -start
7181

7282
stream 1 {
7383
txreq -hdr barrier ${b2_sock}
84+
barrier b2_err sync
7485
txdata -data "fail"
7586
rxrst
7687
expect rst.err == STREAM_CLOSED
7788
barrier b2 sync
7889
} -run
7990

8091
stream 0 -wait
81-
} -run
92+
} -start
93+
94+
logexpect l2 -wait
95+
barrier b2_err sync
96+
97+
client c2 -wait
98+
99+
logexpect l3 -v v1 -g raw {
100+
expect * * ReqMethod POST
101+
expect * = VCL_call DELIVER
102+
} -start
82103

83104
client c3 {
84105
stream 0 {
@@ -96,6 +117,7 @@ client c3 {
96117
stream 1 {
97118
txreq -req "POST" -hdr barrier ${b3_sock} -nostrend
98119
txdata -data "ok"
120+
barrier b3_err sync
99121
txdata -data "fail"
100122
rxrst
101123
expect rst.err == STREAM_CLOSED
@@ -117,4 +139,9 @@ client c3 {
117139
} -run
118140

119141
stream 0 -wait
120-
} -run
142+
} -start
143+
144+
logexpect l3 -wait
145+
barrier b3_err sync
146+
147+
client c3 -wait

bin/varnishtest/tests/t02025.vtc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
varnishtest "h2 reset interrupt"
2+
3+
barrier b1 sock 2
4+
barrier b2 sock 2
5+
6+
varnish v1 -cliok "param.set feature +http2"
7+
varnish v1 -cliok "param.set debug +syncvsl"
8+
varnish v1 -vcl {
9+
import vtc;
10+
11+
backend be none;
12+
13+
sub vcl_recv {
14+
vtc.barrier_sync("${b1_sock}");
15+
vtc.barrier_sync("${b2_sock}");
16+
}
17+
18+
sub vcl_miss {
19+
vtc.panic("unreachable");
20+
}
21+
} -start
22+
23+
logexpect l1 -v v1 -g raw -i Debug {
24+
expect * * Debug "^H2RXF RST_STREAM"
25+
} -start
26+
27+
client c1 {
28+
stream 1 {
29+
txreq
30+
barrier b1 sync
31+
txrst
32+
} -run
33+
} -start
34+
35+
logexpect l1 -wait
36+
barrier b2 sync
37+
38+
varnish v1 -vsl_catchup
39+
varnish v1 -expect req_reset == 1
40+
41+
# NB: The varnishncsa command below shows a minimal pattern to collect
42+
# "rapid reset" suspects per session, with the IP address. Here rapid
43+
# is interpreted as before a second elapsed. Session VXIDs showing up
44+
# numerous times become increasingly more suspicious. The format can of
45+
# course be extended to add anything else useful for data mining.
46+
shell -expect "1000 ${localhost}" {
47+
varnishncsa -n ${v1_name} -d \
48+
-q 'Timestamp:Reset[2] < 1.0' -F '%{VSL:Begin[2]}x %h'
49+
}

doc/sphinx/reference/vsl.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ Restart
7777
Client request is being restarted.
7878

7979
Reset
80-
The client closed its connection or reset its stream. Request
80+
The client closed its connection, reset its stream or caused
81+
a stream error that forced Varnish to reset the stream. Request
8182
processing is interrupted and considered failed.
8283

8384
Pipe handling timestamps

lib/libvsc/VSC_main.vsc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@
350350
:oneliner: Requests reset
351351

352352
Number of times a client left before the VCL processing of its
353-
requests completed.
353+
requests completed. For HTTP/2 sessions, either the stream was
354+
reset by an RST_STREAM frame from the client, or a stream or
355+
connection error occurred.
354356

355357
.. varnish_vsc:: n_object
356358
:type: gauge

0 commit comments

Comments
 (0)