From b6bf8d2076b3b3f99947798b088f16ed6a8d5211 Mon Sep 17 00:00:00 2001 From: mengxiangwei <1031205858@qq.com> Date: Fri, 15 May 2026 16:50:55 +0800 Subject: [PATCH] HTTP/2: log failures in the synchronous request body reader Three failure paths in ngx_http_v2_read_request_body() returned NGX_HTTP_INTERNAL_SERVER_ERROR without writing anything to the error log at any level. As a result, when a client sends RST_STREAM(CANCEL) on an HTTP/2 POST that has already entered proxy_pass, the stream is reset, the subsequent send_window_update() or send_output_queue() fails, the function returns 500, and the access log records status=500 bytes_sent=0 with no matching error_log entry. The buffer allocation path is rarer but silent for the same reason. NGX_LOG_ERR entries are now emitted before each of the three returns. The level is chosen to match the visibility of the 500 already recorded in the access log: operators should see the cause without raising the error_log level. The buffer allocation path also changes its return value from NGX_HTTP_INTERNAL_SERVER_ERROR to NGX_HTTP_INSUFFICIENT_STORAGE. A failed request body buffer allocation is closer in nature to the ENOSPC handling in ngx_http_dav_module than to a generic internal error; the existing 507 status fits better than 500. The other two paths still return 500 -- they reflect stream/connection state, not resource exhaustion. --- src/http/v2/ngx_http_v2.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c index 69cb0ae09..f5f8b4a0b 100644 --- a/src/http/v2/ngx_http_v2.c +++ b/src/http/v2/ngx_http_v2.c @@ -4009,7 +4009,9 @@ ngx_http_v2_read_request_body(ngx_http_request_t *r) if (rb->buf == NULL) { stream->skip_data = 1; - return NGX_HTTP_INTERNAL_SERVER_ERROR; + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "http2 cannot allocate request body buffer"); + return NGX_HTTP_INSUFFICIENT_STORAGE; } buf = stream->preread; @@ -4064,6 +4066,8 @@ ngx_http_v2_read_request_body(ngx_http_request_t *r) == NGX_ERROR) { stream->skip_data = 1; + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "http2 failed to send WINDOW_UPDATE"); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -4072,6 +4076,8 @@ ngx_http_v2_read_request_body(ngx_http_request_t *r) if (!h2c->blocked) { if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) { stream->skip_data = 1; + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "http2 failed to send output queue"); return NGX_HTTP_INTERNAL_SERVER_ERROR; } }