diff src/http/v3/ngx_http_v3_streams.c @ 8903:0d3bf08eaac0 quic

HTTP/3: allowed QUIC stream connection reuse. A QUIC stream connection is treated as reusable until first bytes of request arrive, which is also when the request object is now allocated. A connection closed as a result of draining, is reset with the error code H3_REQUEST_REJECTED. Such behavior is allowed by quic-http-34: Once a request stream has been opened, the request MAY be cancelled by either endpoint. Clients cancel requests if the response is no longer of interest; servers cancel requests if they are unable to or choose not to respond. When the server cancels a request without performing any application processing, the request is considered "rejected." The server SHOULD abort its response stream with the error code H3_REQUEST_REJECTED. The client can treat requests rejected by the server as though they had never been sent at all, thereby allowing them to be retried later.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 18 Oct 2021 15:47:06 +0300
parents 925572184d4a
children d6ef13c5fd8e
line wrap: on
line diff
--- a/src/http/v3/ngx_http_v3_streams.c
+++ b/src/http/v3/ngx_http_v3_streams.c
@@ -49,7 +49,8 @@ ngx_http_v3_init_uni_stream(ngx_connecti
         ngx_http_v3_finalize_connection(c,
                                       NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR,
                                       "reached maximum number of uni streams");
-        ngx_http_close_connection(c);
+        c->data = NULL;
+        ngx_http_v3_close_uni_stream(c);
         return;
     }
 
@@ -57,7 +58,11 @@ ngx_http_v3_init_uni_stream(ngx_connecti
 
     us = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_uni_stream_t));
     if (us == NULL) {
-        ngx_http_close_connection(c);
+        ngx_http_v3_finalize_connection(c,
+                                        NGX_HTTP_V3_ERR_INTERNAL_ERROR,
+                                        "memory allocation error");
+        c->data = NULL;
+        ngx_http_v3_close_uni_stream(c);
         return;
     }
 
@@ -79,12 +84,12 @@ ngx_http_v3_close_uni_stream(ngx_connect
     ngx_http_v3_session_t     *h3c;
     ngx_http_v3_uni_stream_t  *us;
 
-    us = c->data;
-    h3c = ngx_http_v3_get_session(c);
-
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 close stream");
 
-    if (us->index >= 0) {
+    us = c->data;
+
+    if (us && us->index >= 0) {
+        h3c = ngx_http_v3_get_session(c);
         h3c->known_streams[us->index] = NULL;
     }