Mailing List Archive

[6.0] cd48ced78 h2: Send GOAWAY frames in a dedicated function
commit cd48ced78d5363171913cf7882b855ad3c40ddcd
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Tue Jan 18 10:08:33 2022 +0100

h2: Send GOAWAY frames in a dedicated function

And after issuing or receiving a goaway, stop processing frames when
there are no streams left.

Initially submitted as part of listen sockets management.

Refs #3959

Conflicts:
bin/varnishd/http2/cache_http2_proto.c

diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h
index e5cf6a224..d0dbb4e35 100644
--- a/bin/varnishd/http2/cache_http2.h
+++ b/bin/varnishd/http2/cache_http2.h
@@ -163,6 +163,7 @@ struct h2_sess {
struct sess *sess;
int refcnt;
uint32_t highest_stream;
+ int goaway;
int bogosity;
int do_sweep;

diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index 1372074cb..ccce69f0e 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -381,6 +381,7 @@ h2_rx_goaway(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC);
assert(r2 == h2->req0);

+ h2->goaway = 1;
h2->goaway_last_stream = vbe32dec(h2->rxf_data);
h2->error = h2_connectionerror(vbe32dec(h2->rxf_data + 4));
Lck_Lock(&h2->sess->mtx);
@@ -389,6 +390,25 @@ h2_rx_goaway(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
return (h2->error);
}

+static void
+h2_tx_goaway(struct worker *wrk, struct h2_sess *h2, h2_error h2e)
+{
+ char b[8];
+
+ ASSERT_RXTHR(h2);
+ AN(h2e);
+
+ if (h2->goaway)
+ return;
+
+ h2->goaway = 1;
+ vbe32enc(b, h2->highest_stream);
+ vbe32enc(b + 4, h2e->val);
+ H2_Send_Get(wrk, h2, h2->req0);
+ H2_Send_Frame(wrk, h2, H2_F_GOAWAY, 0, 8, 0, b);
+ H2_Send_Rel(h2, h2->req0);
+}
+
/**********************************************************************
*/

@@ -1410,9 +1430,12 @@ h2_rxframe(struct worker *wrk, struct h2_sess *h2)
enum htc_status_e hs;
h2_frame h2f;
h2_error h2e;
- char b[8];

ASSERT_RXTHR(h2);
+
+ if (h2->goaway && h2->open_streams == 0)
+ return (0);
+
VTCP_blocking(*h2->htc->rfd);
h2->sess->t_idle = VTIM_real();
hs = HTC_RxStuff(h2->htc, h2_frame_complete,
@@ -1484,11 +1507,7 @@ h2_rxframe(struct worker *wrk, struct h2_sess *h2)
h2e = h2_procframe(wrk, h2, h2f);
if (h2->error == NULL && h2e != NULL) {
h2->error = h2e;
- vbe32enc(b, h2->highest_stream);
- vbe32enc(b + 4, h2e->val);
- H2_Send_Get(wrk, h2, h2->req0);
- H2_Send_Frame(wrk, h2, H2_F_GOAWAY, 0, 8, 0, b);
- H2_Send_Rel(h2, h2->req0);
+ h2_tx_goaway(wrk, h2, h2e);
}

return (h2->error != NULL ? 0 : 1);
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit