[PATCH 11 of 15] Tempfiles: reset c->body_start when updating a tempfile

Jiří Setnička jiri.setnicka at cdn77.com
Fri Jan 28 16:32:03 UTC 2022


# HG changeset patch
# User Jiří Setnička  <jiri.setnicka at cdn77.com>
# Date 1643385660 -3600
#      Fri Jan 28 17:01:00 2022 +0100
# Node ID 64a2e216aeeeb847eb0b9a83ed6e6082ade4ac9e
# Parent  bd12e8ba1af2005260e68a410e3c8927a88dac1a
Tempfiles: reset c->body_start when updating a tempfile
Previously when there was an old cached file and multiple concurrent
requests to it, the first requets created a new tempfile and other
requests tried to open this tempfile - but with c->body_start from the
original file.

This could result in critical errors "cache file .. has too long header".

diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -402,7 +402,9 @@ ngx_http_file_cache_open(ngx_http_reques
         cln->data = c;
     }
 
-    c->buffer_size = c->body_start;
+    if (c->buffer_size < c->body_start) {
+        c->buffer_size = c->body_start;
+    }
 
     rc = ngx_http_file_cache_exists(cache, c);
 
@@ -560,6 +562,8 @@ ngx_http_file_cache_open_temp_file(ngx_h
 
     ngx_shmtx_unlock(&cache->shpool->mutex);
 
+    c->body_start = c->buffer_size;
+
     if (c->tf_node == NULL) {
         rc = ngx_http_file_cache_wait_for_temp_file(r, c);
 


More information about the nginx-devel mailing list