Welcome! Log In Create A New Profile

Advanced

Re: Опять "cache file has too long header"

Maxim Dounin
September 07, 2017 12:56PM
Hello!

On Thu, Sep 07, 2017 at 06:33:19AM -0400, Ilya Evseev wrote:

> Написал патч для более подробной диагностики:
> https://gist.github.com/ilyaevseev/f2c57519db829329f8e9f9aff5d51789
>
> Попутно нашел ошибку в Nginx:
> 1) wget http://nginx-frontend/cached-upstream-file
> 2) ищем на nginx-сервере файл в кэше, удаляем всё, начиная от пары последних
> строк заголовка HTTP-ответа
> 3) повторяем wget и он подвисает: "HTTP-запрос отправлен. Ожидание ответа...
> Не получено никаких данных."

Патч ниже должен помочь.

# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1504803092 -10800
# Thu Sep 07 19:51:32 2017 +0300
# Node ID 74c7990ae3c7a7c4a8779ea6340d044108e24e98
# Parent 97e138ddbfcb476f583d95ea74ff0eb27e81478a
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.

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -582,6 +582,8 @@ ngx_http_upstream_init_request(ngx_http_
if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
rc = NGX_DECLINED;
r->cached = 0;
+ u->buffer.start = NULL;
+ u->cache_status = NGX_HTTP_CACHE_MISS;
}

if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) {
@@ -1059,8 +1061,16 @@ ngx_http_upstream_cache_send(ngx_http_re
return NGX_ERROR;
}

+ if (rc == NGX_AGAIN) {
+ rc = NGX_HTTP_UPSTREAM_INVALID_HEADER;
+ }
+
/* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */

+ ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
+ "cache file \"%s\" contains invalid header",
+ c->file.name.data);
+
/* TODO: delete file */

return rc;


--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

Опять "cache file has too long header"

Ilya Evseev September 06, 2017 10:33AM

Re: Опять "cache file has too long header"

Ilya Evseev September 07, 2017 06:33AM

Re: Опять "cache file has too long header"

Maxim Dounin September 07, 2017 12:56PM

Re: Опять "cache file has too long header"

Ilya Evseev September 08, 2017 04:40AM

Re: Опять "cache file has too long header"

Maxim Dounin September 08, 2017 08:42AM

Re: Опять "cache file has too long header"

Ilya Evseev September 08, 2017 09:09AM

Re: Опять "cache file has too long header"

Maxim Dounin September 08, 2017 09:22AM

Re: Опять "cache file has too long header"

Ilya Evseev September 08, 2017 10:32AM

Re: Опять "cache file has too long header"

Maxim Dounin September 08, 2017 11:00AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 312
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