Sergey Kandaurov
February 03, 2023 06:14AM
details: https://hg.nginx.org/nginx/rev/f5515e727656
branches:
changeset: 8124:f5515e727656
user: Maxim Dounin <mdounin@mdounin.ru>
date: Sat Jan 28 05:23:33 2023 +0300
description:
Fixed "zero size buf" alerts with subrequests.

Since 4611:2b6cb7528409 responses from the gzip static, flv, and mp4 modules
can be used with subrequests, though empty files were not properly handled.
Empty gzipped, flv, and mp4 files thus resulted in "zero size buf in output"
alerts. While valid corresponding files are not expected to be empty, such
files shouldn't result in alerts.

Fix is to set b->sync on such empty subrequest responses, similarly to what
ngx_http_send_special() does.

Additionally, the static module, the ngx_http_send_response() function, and
file cache are modified to do the same instead of not sending the response
body at all in such cases, since not sending the response body at all is
believed to be at least questionable, and might break various filters
which do not expect such behaviour.

diffstat:

src/http/modules/ngx_http_flv_module.c | 1 +
src/http/modules/ngx_http_gzip_static_module.c | 1 +
src/http/modules/ngx_http_mp4_module.c | 1 +
src/http/modules/ngx_http_static_module.c | 5 +----
src/http/ngx_http_core_module.c | 5 +----
src/http/ngx_http_file_cache.c | 5 +----
6 files changed, 6 insertions(+), 12 deletions(-)

diffs (99 lines):

diff -r 1c3b78d7cdc9 -r f5515e727656 src/http/modules/ngx_http_flv_module.c
--- a/src/http/modules/ngx_http_flv_module.c Sat Jan 28 05:20:23 2023 +0300
+++ b/src/http/modules/ngx_http_flv_module.c Sat Jan 28 05:23:33 2023 +0300
@@ -235,6 +235,7 @@ ngx_http_flv_handler(ngx_http_request_t
b->in_file = b->file_last ? 1 : 0;
b->last_buf = (r == r->main) ? 1 : 0;
b->last_in_chain = 1;
+ b->sync = (b->last_buf || b->in_file) ? 0 : 1;

b->file->fd = of.fd;
b->file->name = path;
diff -r 1c3b78d7cdc9 -r f5515e727656 src/http/modules/ngx_http_gzip_static_module.c
--- a/src/http/modules/ngx_http_gzip_static_module.c Sat Jan 28 05:20:23 2023 +0300
+++ b/src/http/modules/ngx_http_gzip_static_module.c Sat Jan 28 05:23:33 2023 +0300
@@ -273,6 +273,7 @@ ngx_http_gzip_static_handler(ngx_http_re
b->in_file = b->file_last ? 1 : 0;
b->last_buf = (r == r->main) ? 1 : 0;
b->last_in_chain = 1;
+ b->sync = (b->last_buf || b->in_file) ? 0 : 1;

b->file->fd = of.fd;
b->file->name = path;
diff -r 1c3b78d7cdc9 -r f5515e727656 src/http/modules/ngx_http_mp4_module.c
--- a/src/http/modules/ngx_http_mp4_module.c Sat Jan 28 05:20:23 2023 +0300
+++ b/src/http/modules/ngx_http_mp4_module.c Sat Jan 28 05:23:33 2023 +0300
@@ -714,6 +714,7 @@ ngx_http_mp4_handler(ngx_http_request_t
b->in_file = b->file_last ? 1 : 0;
b->last_buf = (r == r->main) ? 1 : 0;
b->last_in_chain = 1;
+ b->sync = (b->last_buf || b->in_file) ? 0 : 1;

b->file->fd = of.fd;
b->file->name = path;
diff -r 1c3b78d7cdc9 -r f5515e727656 src/http/modules/ngx_http_static_module.c
--- a/src/http/modules/ngx_http_static_module.c Sat Jan 28 05:20:23 2023 +0300
+++ b/src/http/modules/ngx_http_static_module.c Sat Jan 28 05:23:33 2023 +0300
@@ -238,10 +238,6 @@ ngx_http_static_handler(ngx_http_request
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

- if (r != r->main && of.size == 0) {
- return ngx_http_send_header(r);
- }
-
r->allow_ranges = 1;

/* we need to allocate all before the header would be sent */
@@ -268,6 +264,7 @@ ngx_http_static_handler(ngx_http_request
b->in_file = b->file_last ? 1 : 0;
b->last_buf = (r == r->main) ? 1 : 0;
b->last_in_chain = 1;
+ b->sync = (b->last_buf || b->in_file) ? 0 : 1;

b->file->fd = of.fd;
b->file->name = path;
diff -r 1c3b78d7cdc9 -r f5515e727656 src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c Sat Jan 28 05:20:23 2023 +0300
+++ b/src/http/ngx_http_core_module.c Sat Jan 28 05:23:33 2023 +0300
@@ -1803,10 +1803,6 @@ ngx_http_send_response(ngx_http_request_
}
}

- if (r != r->main && val.len == 0) {
- return ngx_http_send_header(r);
- }
-
b = ngx_calloc_buf(r->pool);
if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -1817,6 +1813,7 @@ ngx_http_send_response(ngx_http_request_
b->memory = val.len ? 1 : 0;
b->last_buf = (r == r->main) ? 1 : 0;
b->last_in_chain = 1;
+ b->sync = (b->last_buf || b->memory) ? 0 : 1;

out.buf = b;
out.next = NULL;
diff -r 1c3b78d7cdc9 -r f5515e727656 src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c Sat Jan 28 05:20:23 2023 +0300
+++ b/src/http/ngx_http_file_cache.c Sat Jan 28 05:23:33 2023 +0300
@@ -1575,10 +1575,6 @@ ngx_http_cache_send(ngx_http_request_t *
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http file cache send: %s", c->file.name.data);

- if (r != r->main && c->length - c->body_start == 0) {
- return ngx_http_send_header(r);
- }
-
/* we need to allocate all before the header would be sent */

b = ngx_calloc_buf(r->pool);
@@ -1603,6 +1599,7 @@ ngx_http_cache_send(ngx_http_request_t *
b->in_file = (c->length - c->body_start) ? 1 : 0;
b->last_buf = (r == r->main) ? 1 : 0;
b->last_in_chain = 1;
+ b->sync = (b->last_buf || b->in_file) ? 0 : 1;

b->file->fd = c->file.fd;
b->file->name = c->file.name;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Fixed "zero size buf" alerts with subrequests.

Sergey Kandaurov 489 February 03, 2023 06:14AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 183
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready