[PATCH 06 of 10] HTTP/2: reset reusable connection status on stream creation

Maxim Dounin mdounin at mdounin.ru
Tue Nov 24 00:27:09 UTC 2026


# HG changeset patch
# User Roman Arutyunyan <arut at nginx.com>
# Date 1789647011 -14400
#      Thu Sep 17 16:10:11 2026 +0400
# Node ID 3ca0668f28f7ebf64b5a458959ed9fe9356b0438
# Parent  719ce1a193bf691cf9d3bc933d81cb5755922b33
HTTP/2: reset reusable connection status on stream creation.

Previously, an HTTP/2 connection could be reusable while having streams.
This could result in an attempt to drain the connection while processing
one if its streams, for example when connecting to an upstream.  After
recognizing that the connection has streams, an attempt to send the
GOAWAY frame was made.  On send failure, the connection was immediately
closed and its pool released.  This triggered a use-after-free up the
stack.

Having an HTTP/2 connection with streams registered as reusable became
possible after 76672e650.  A connection with no streams and a partial
frame read from client was registered as reusable to avoid DoS attacks.
So if a client sends only the first HEADERS frame byte, the connection
becomes reusable.  Later, when the remaining HEADERS bytes are received
and a new stream is created, the reusable status is not reset until the
connection becomes idle.

Fix is to mark the connection non-reusable upon stream creation.

Reported by Albert @ Vexera AI.

Obtained from:
https://github.com/nginx/nginx/commit/2df48a501d0fb8212b7d39dffeeff5876332ba59

diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -3158,6 +3158,8 @@ ngx_http_v2_create_stream(ngx_http_v2_co
 
     h2c->processing++;
 
+    ngx_reusable_connection(h2c->connection, 0);
+
     h2c->priority_limit += h2scf->concurrent_streams;
 
     if (h2c->connection->read->timer_set) {



More information about the nginx-devel mailing list