Klaus Demo nginx / 105dd42
Upstream: better handling of invalid headers in cache files. If cache file is truncated, it is possible that u->process_header() will return NGX_AGAIN. Added appropriate handling of this case by changing the error to NGX_HTTP_UPSTREAM_INVALID_HEADER. Also, added appropriate logging of this and NGX_HTTP_UPSTREAM_INVALID_HEADER cases at the "crit" level. Note that this will result in duplicate logging in case of NGX_HTTP_UPSTREAM_INVALID_HEADER. While this is something better to avoid, it is considered to be an overkill to implement cache-specific error logging in u->process_header(). Additionally, u->buffer.start is now reset to be able to receive a new response, and u->cache_status set to MISS to provide the value in the $upstream_cache_status variable, much like it happens on other cache file errors detected by ngx_http_file_cache_read(), instead of HIT, which is believed to be misleading. Maxim Dounin 2 years ago
1 changed file(s) with 10 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
581581 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
582582 rc = NGX_DECLINED;
583583 r->cached = 0;
584 u->buffer.start = NULL;
585 u->cache_status = NGX_HTTP_CACHE_MISS;
584586 }
585587
586588 if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) {
10581060 return NGX_ERROR;
10591061 }
10601062
1063 if (rc == NGX_AGAIN) {
1064 rc = NGX_HTTP_UPSTREAM_INVALID_HEADER;
1065 }
1066
10611067 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */
1068
1069 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
1070 "cache file \"%s\" contains invalid header",
1071 c->file.name.data);
10621072
10631073 /* TODO: delete file */
10641074