]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoHTTP/2: removed http2_recv_timeout.
Maxim Dounin [Thu, 11 Feb 2021 18:52:20 +0000 (21:52 +0300)]
HTTP/2: removed http2_recv_timeout.

Instead, the client_header_timeout is now used for HTTP/2 reading.
Further, the timeout is changed to be set once till no further data
left to read, similarly to how client_header_timeout is used in other
places.

5 years agoHTTP/2: removed SPDY directives handling.
Maxim Dounin [Thu, 11 Feb 2021 18:52:19 +0000 (21:52 +0300)]
HTTP/2: removed SPDY directives handling.

The spdy_* directives are not available since introduction of HTTP/2 module
in nginx 1.9.5 more than five years ago.

5 years agoHTTP/2: fixed reusing connections with active requests.
Maxim Dounin [Thu, 11 Feb 2021 18:52:17 +0000 (21:52 +0300)]
HTTP/2: fixed reusing connections with active requests.

New connections are marked reusable by ngx_http_init_connection() if there
are no data available for reading.  As a result, if SSL is not used,
ngx_http_v2_init() might be called when the connection is marked reusable.
If a HEADERS frame is immediately available for reading, this resulted
in connection being preserved in reusable state with an active request,
and possibly closed later as if during worker shutdown (that is, after
all active requests were finalized).

Fix is to explicitly mark connections non-reusable in ngx_http_v2_init()
instead of (incorrectly) assuming they are already non-reusable.

Found by Sergey Kandaurov.

5 years agoHTTP/2: reuse of connections with incomplete frames.
Maxim Dounin [Thu, 11 Feb 2021 18:52:12 +0000 (21:52 +0300)]
HTTP/2: reuse of connections with incomplete frames.

Prodded by Taewoo Kim.

5 years agoAdditional connections reuse.
Maxim Dounin [Thu, 11 Feb 2021 18:52:11 +0000 (21:52 +0300)]
Additional connections reuse.

If ngx_drain_connections() fails to immediately reuse any connections
and there are no free connections, it now additionally tries to reuse
a connection again.  This helps to provide at least one free connection
in case of HTTP/2 with lingering close, where merely trying to reuse
a connection once does not free it, but makes it reusable again,
waiting for lingering close.

5 years agoReuse of connections in lingering close.
Maxim Dounin [Thu, 11 Feb 2021 18:52:09 +0000 (21:52 +0300)]
Reuse of connections in lingering close.

This is particularly important in HTTP/2, where keepalive connections
are closed with lingering.  Before the patch, reusing a keepalive HTTP/2
connection resulted in the connection waiting for lingering close to
remain in the reusable connections queue, preventing ngx_drain_connections()
from closing additional connections.

The patch fixes it by marking the connection reusable again, and so
moving it in the reusable connections queue.  Further, it makes actually
possible to reuse such connections if needed.

5 years agoHTTP/2: lingering close changed to handle NGX_AGAIN.
Ruslan Ermilov [Mon, 1 Feb 2021 13:42:50 +0000 (16:42 +0300)]
HTTP/2: lingering close changed to handle NGX_AGAIN.

This part somehow slipped away from c5840ca2063d.

While it is not expected to be needed in case of lingering close,
it is good to keep it for correctness (see 2b5528023f6b).

5 years agoClean up trailers in ngx_http_clean_header() as well.
Sergey Kandaurov [Tue, 26 Jan 2021 09:39:28 +0000 (12:39 +0300)]
Clean up trailers in ngx_http_clean_header() as well.

The function has not been updated with introduction of trailers support
in 7034:1b068a4e82d8 (1.13.2).

5 years agoYear 2021.
Maxim Dounin [Tue, 19 Jan 2021 17:35:17 +0000 (20:35 +0300)]
Year 2021.

5 years agoCore: removed post_accept_timeout.
Maxim Dounin [Tue, 19 Jan 2021 17:32:00 +0000 (20:32 +0300)]
Core: removed post_accept_timeout.

Keeping post_accept_timeout in ngx_listening_t is no longer needed since
we've switched to 1 second timeout for deferred accept in 5541:fdb67cfc957d.

Further, using it in HTTP code can result in client_header_timeout being
used from an incorrect server block, notably if address-specific virtual
servers are used along with a wildcard listening socket, or if we've switched
to a different server block based on SNI in SSL handshake.

5 years agoRemoved incorrect optimization of HEAD requests.
Maxim Dounin [Tue, 19 Jan 2021 17:21:12 +0000 (20:21 +0300)]
Removed incorrect optimization of HEAD requests.

The stub status module and ngx_http_send_response() (used by the empty gif
module and the "return" directive) incorrectly assumed that responding
to HEAD requests always results in r->header_only being set.  This is not
true, and results in incorrect behaviour, for example, in the following
configuration:

   location / {
       image_filter size;
       return 200 test;
   }

Fix is to remove this incorrect micro-optimization from both stub status
module and ngx_http_send_response().

Reported by Chris Newton.

5 years agoUpstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin [Tue, 12 Jan 2021 13:59:31 +0000 (16:59 +0300)]
Upstream: fixed zero size buf alerts on extra data (ticket #2117).

After 7675:9afa45068b8f and 7678:bffcc5af1d72 (1.19.1), during non-buffered
simple proxying, responses with extra data might result in zero size buffers
being generated and "zero size buf" alerts in writer.  This bug is similar
to the one with FastCGI proxying fixed in 7689:da8d758aabeb.

In non-buffered mode, normally the filter function is not called if
u->length is already 0, since u->length is checked after each call of
the filter function.  There is a case when this can happen though: if
the response length is 0, and there are pre-read response body data left
after reading response headers.  As such, a check for u->length is needed
at the start of non-buffered filter functions, similar to the one
for p->length present in buffered filter functions.

Appropriate checks added to the existing non-buffered copy filters
in the upstream (used by scgi and uwsgi proxying) and proxy modules.

5 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Tue, 29 Dec 2020 11:13:57 +0000 (13:13 +0200)]
Contrib: vim syntax, update core and 3rd party module directives.

5 years agoVersion bump.
Maxim Dounin [Mon, 11 Jan 2021 19:06:27 +0000 (22:06 +0300)]
Version bump.

5 years agorelease-1.19.6 tag
Maxim Dounin [Tue, 15 Dec 2020 14:41:39 +0000 (17:41 +0300)]
release-1.19.6 tag

5 years agonginx-1.19.6-RELEASE release-1.19.6
Maxim Dounin [Tue, 15 Dec 2020 14:41:39 +0000 (17:41 +0300)]
nginx-1.19.6-RELEASE

5 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 15 Dec 2020 13:49:24 +0000 (16:49 +0300)]
Updated OpenSSL used for win32 builds.

5 years agoFixed double close of non-regular files in flv and mp4.
Maxim Dounin [Fri, 11 Dec 2020 10:42:07 +0000 (13:42 +0300)]
Fixed double close of non-regular files in flv and mp4.

With introduction of open_file_cache in 1454:f497ed7682a7, opening a file
with ngx_open_cached_file() automatically adds a cleanup handler to close
the file.  As such, calling ngx_close_file() directly for non-regular files
is no longer needed and will result in duplicate close() call.

In 1454:f497ed7682a7 ngx_close_file() call for non-regular files was removed
in the static module, but wasn't in the flv module.  And the resulting
incorrect code was later copied to the mp4 module.  Fix is to remove the
ngx_close_file() call from both modules.

Reported by Chris Newton.

5 years agoRemoved extra allocation for r->uri.
Maxim Dounin [Thu, 10 Dec 2020 17:09:39 +0000 (20:09 +0300)]
Removed extra allocation for r->uri.

The ngx_http_parse_complex_uri() function cannot make URI longer and does
not null-terminate URI, so there is no need to allocate an extra byte.  This
allocation appears to be a leftover from changes in 461:a88a3e4e158f (0.1.5),
where null-termination of r->uri and many other strings was removed.

5 years agoFixed parsing of absolute URIs with empty path (ticket #2079).
Maxim Dounin [Thu, 10 Dec 2020 17:09:30 +0000 (20:09 +0300)]
Fixed parsing of absolute URIs with empty path (ticket #2079).

When the request line contains request-target in the absolute-URI form,
it can contain path-empty instead of a single slash (see RFC 7230, RFC 3986).
Previously, the ngx_http_parse_request_line() function only accepted empty
path when there was no query string.

With this change, non-empty query is also correctly handled.  That is,
request line "GET http://example.com?foo HTTP/1.1" is accepted and results
in $uri "/" and $args "foo".

Note that $request_uri remains "?foo", similarly to how spaces in URIs
are handled.  Providing "/?foo", similarly to how "/" is provided for
"GET http://example.com HTTP/1.1", requires allocation.

5 years agoSSL: fixed SSL shutdown on lingering close.
Ruslan Ermilov [Mon, 7 Dec 2020 22:43:36 +0000 (01:43 +0300)]
SSL: fixed SSL shutdown on lingering close.

Ensure c->recv is properly reset to ngx_recv if SSL_shutdown()
blocks on writing.

The bug had appeared in 554c6ae25ffc.

5 years agoUpstream: excluded down servers from the next_upstream tries.
Ruslan Ermilov [Thu, 26 Nov 2020 21:01:20 +0000 (00:01 +0300)]
Upstream: excluded down servers from the next_upstream tries.

Previously, the number of next_upstream tries included servers marked
as "down", resulting in "no live upstreams" with the code 502 instead
of the code derived from an attempt to connect to the last tried "up"
server (ticket #2096).

5 years agoVersion bump.
Ruslan Ermilov [Thu, 26 Nov 2020 20:46:59 +0000 (23:46 +0300)]
Version bump.

5 years agorelease-1.19.5 tag
Maxim Dounin [Tue, 24 Nov 2020 15:06:34 +0000 (18:06 +0300)]
release-1.19.5 tag

5 years agonginx-1.19.5-RELEASE release-1.19.5
Maxim Dounin [Tue, 24 Nov 2020 15:06:34 +0000 (18:06 +0300)]
nginx-1.19.5-RELEASE

5 years agogRPC: RST_STREAM(NO_ERROR) handling after "trailer only" responses.
Pavel Pautov [Thu, 19 Nov 2020 02:41:16 +0000 (18:41 -0800)]
gRPC: RST_STREAM(NO_ERROR) handling after "trailer only" responses.

Similarly to the problem fixed in 2096b21fcd10 (ticket #1792),
when a "trailer only" gRPC response (that is, a response with the
END_STREAM flag in the HEADERS frame) was immediately followed by
RST_STREAM(NO_ERROR) in the data preread along with the response
header, RST_STREAM wasn't properly skipped and caused "upstream
rejected request with error 0" errors.
Observed with "unknown service" gRPC errors returned by grpc-go.

Fix is to set ctx->done if we are going to parse additional data,
so the RST_STREAM(NO_ERROR) is properly skipped.  Additionally, now
ngx_http_grpc_filter() will complain about frames sent for closed
stream if there are any.

5 years agoUse .Mt to mark up email addresses.
Sergey Kandaurov [Thu, 19 Nov 2020 17:15:22 +0000 (17:15 +0000)]
Use .Mt to mark up email addresses.

5 years agoCore: "-e" command line option.
Igor Ippolitov [Thu, 19 Nov 2020 16:59:00 +0000 (16:59 +0000)]
Core: "-e" command line option.

When installing or running from a non-root user it is sometimes required to
override default, compiled in error log path. There was no way to do this
without rebuilding the binary (ticket #147).

This patch introduced "-e" command line option which allows one to override
compiled in error log path.

5 years agoConfigure: shared sources for addon modules.
Maxim Dounin [Tue, 10 Nov 2020 14:13:20 +0000 (17:13 +0300)]
Configure: shared sources for addon modules.

Addon modules, both dynamic and static, can now use shared source files.
Shared sources result in only one make rule even if specified several
times in different modules.

5 years agoConfigure: initialization of NGX_ADDON_SRCS.
Maxim Dounin [Tue, 10 Nov 2020 14:13:17 +0000 (17:13 +0300)]
Configure: initialization of NGX_ADDON_SRCS.

5 years agoConfigure: style.
Maxim Dounin [Tue, 10 Nov 2020 14:13:14 +0000 (17:13 +0300)]
Configure: style.

5 years agoRequest body: removed error assumption (ticket #2058).
Maxim Dounin [Mon, 9 Nov 2020 19:41:54 +0000 (22:41 +0300)]
Request body: removed error assumption (ticket #2058).

Before introduction of request body filter in 42d9beeb22db, the only
possible return code from the ngx_http_request_body_filter() call
without actual buffers was NGX_HTTP_INTERNAL_SERVER_ERROR, and
the code in ngx_http_read_client_request_body() hardcoded the only
possible error to simplify the code of initial call to set rb->rest.

This is no longer true after introduction of request body filters though,
as a request body filter might need to return other errors, such as 403.
Fix is to preserve the error code actually returned by the call
instead of assuming 500.

5 years agoRequest body: improved logging.
Maxim Dounin [Mon, 9 Nov 2020 19:40:53 +0000 (22:40 +0300)]
Request body: improved logging.

Added logging before returning NGX_HTTP_INTERNAL_SERVER_ERROR if there
are busy buffers after a request body flush.  This should never happen
with current code, though bugs can be introduced by 3rd party modules.
Make sure debugging will be easy enough.

5 years agoSSL: fixed non-working SSL shutdown on lingering close.
Ruslan Ermilov [Fri, 6 Nov 2020 20:44:54 +0000 (23:44 +0300)]
SSL: fixed non-working SSL shutdown on lingering close.

When doing lingering close, the socket was first shut down for writing,
so SSL shutdown initiated after lingering close was not able to send
the close_notify alerts (ticket #2056).

The fix is to call ngx_ssl_shutdown() before shutting down the socket.

5 years agoRemoved dead code from ngx_http_set_keepalive().
Ruslan Ermilov [Fri, 6 Nov 2020 20:44:47 +0000 (23:44 +0300)]
Removed dead code from ngx_http_set_keepalive().

The code removed became dead after 98f03cd8d6cc (0.8.14),
circa when the request reference counting was introduced.

5 years agoCore: added format specifiers to output binary data as hex.
Vladimir Homutov [Wed, 28 Oct 2020 07:56:11 +0000 (10:56 +0300)]
Core: added format specifiers to output binary data as hex.

Now "s", "V", and "v" format specifiers may be prefixed with "x" (lowercase)
or "X" (uppercase) to output corresponding data in hexadecimal format.

In collaboration with Maxim Dounin.

5 years agoVersion bump.
Vladimir Homutov [Thu, 5 Nov 2020 19:37:27 +0000 (22:37 +0300)]
Version bump.

5 years agorelease-1.19.4 tag
Maxim Dounin [Tue, 27 Oct 2020 15:09:20 +0000 (18:09 +0300)]
release-1.19.4 tag

5 years agonginx-1.19.4-RELEASE release-1.19.4
Maxim Dounin [Tue, 27 Oct 2020 15:09:20 +0000 (18:09 +0300)]
nginx-1.19.4-RELEASE

5 years agoSSL: ssl_reject_handshake directive (ticket #195).
Maxim Dounin [Thu, 22 Oct 2020 15:02:28 +0000 (18:02 +0300)]
SSL: ssl_reject_handshake directive (ticket #195).

In some cases it might be needed to reject SSL handshake based on SNI
server name provided, for example, to make sure an invalid certificate
is not returned to clients trying to contact a name-based virtual server
without SSL configured.  Previously, a "ssl_ciphers aNULL;" was used for
this.  This workaround, however, is not compatible with TLSv1.3, in
particular, when using BoringSSL, where it is not possible to configure
TLSv1.3 ciphers at all.

With this change, the ssl_reject_handshake directive is introduced,
which instructs nginx to reject SSL handshakes with an "unrecognized_name"
alert in a particular server block.

For example, to reject handshake with names other than example.com,
one can use the following configuration:

    server {
        listen 443 ssl;
        ssl_reject_handshake on;
    }

    server {
        listen 443 ssl;
        server_name example.com;
        ssl_certificate example.com.crt;
        ssl_certificate_key example.com.key;
    }

The following configuration can be used to reject all SSL handshakes
without SNI server name provided:

    server {
        listen 443 ssl;
        ssl_reject_handshake on;
    }

    server {
        listen 443 ssl;
        server_name ~^;
        ssl_certificate example.crt;
        ssl_certificate_key example.key;
    }

Additionally, the ssl_reject_handshake directive makes configuring
certificates for the default server block optional.  If no certificates
are configured in the default server for a given listening socket,
certificates must be defined in all non-default server blocks with
the listening socket in question.

5 years agoStream: proxy_ssl_conf_command directive.
Maxim Dounin [Thu, 22 Oct 2020 15:00:27 +0000 (18:00 +0300)]
Stream: proxy_ssl_conf_command directive.

Similarly to ssl_conf_command, proxy_ssl_conf_command can be used to
set arbitrary OpenSSL configuration parameters as long as nginx is
compiled with OpenSSL 1.0.2 or later, when connecting to upstream
servers with SSL.  Full list of available configuration commands
can be found in the SSL_CONF_cmd manual page
(https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).

5 years agoUpstream: proxy_ssl_conf_command and friends.
Maxim Dounin [Thu, 22 Oct 2020 15:00:23 +0000 (18:00 +0300)]
Upstream: proxy_ssl_conf_command and friends.

Similarly to ssl_conf_command, proxy_ssl_conf_command (grpc_ssl_conf_command,
uwsgi_ssl_conf_command) can be used to set arbitrary OpenSSL configuration
parameters as long as nginx is compiled with OpenSSL 1.0.2 or later,
when connecting to upstream servers with SSL.  Full list of available
configuration commands can be found in the SSL_CONF_cmd manual page
(https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).

5 years agoSSL: ssl_conf_command directive.
Maxim Dounin [Thu, 22 Oct 2020 15:00:22 +0000 (18:00 +0300)]
SSL: ssl_conf_command directive.

With the ssl_conf_command directive it is now possible to set
arbitrary OpenSSL configuration parameters as long as nginx is compiled
with OpenSSL 1.0.2 or later.  Full list of available configuration
commands can be found in the SSL_CONF_cmd manual page
(https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).

In particular, this allows configuring PrioritizeChaCha option
(ticket #1445):

    ssl_conf_command Options PrioritizeChaCha;

It can be also used to configure TLSv1.3 ciphers in OpenSSL,
which fails to configure them via the SSL_CTX_set_cipher_list()
interface (ticket #1529):

    ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;

Configuration commands are applied after nginx own configuration
for SSL, so they can be used to override anything set by nginx.
Note though that configuring OpenSSL directly with ssl_conf_command
might result in a behaviour nginx does not expect, and should be
done with care.

5 years agoCore: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR.
Maxim Dounin [Thu, 22 Oct 2020 15:00:20 +0000 (18:00 +0300)]
Core: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR.

With this change, it is now possible to use ngx_conf_merge_ptr_value()
to merge keyval arrays.  This change actually follows much earlier
changes in ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot()
in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22).

To preserve compatibility with existing 3rd party modules, both NULL
and NGX_CONF_UNSET_PTR are accepted for now.

5 years agoCpp test: added stream.
Ruslan Ermilov [Tue, 13 Oct 2020 04:44:09 +0000 (07:44 +0300)]
Cpp test: added stream.

5 years agoLimit req: unlocking of nodes on complex value errors.
Maxim Dounin [Thu, 8 Oct 2020 14:44:34 +0000 (17:44 +0300)]
Limit req: unlocking of nodes on complex value errors.

Previously, if there were multiple limits configured, errors in
ngx_http_complex_value() during processing of a non-first limit
resulted in reference count leak in shared memory nodes of already
processed limits.  Fix is to explicity unlock relevant nodes, much
like we do when rejecting requests.

5 years agoMail: proxy_smtp_auth directive.
Maxim Dounin [Sat, 3 Oct 2020 18:04:57 +0000 (21:04 +0300)]
Mail: proxy_smtp_auth directive.

The proxy_smtp_auth directive instructs nginx to authenticate users
on backend via the AUTH command (using the PLAIN SASL mechanism),
similar to what is normally done for IMAP and POP3.

If xclient is enabled along with proxy_smtp_auth, the XCLIENT command
won't try to send the LOGIN parameter.

5 years agoVersion bump.
Maxim Dounin [Sat, 3 Oct 2020 18:01:12 +0000 (21:01 +0300)]
Version bump.

5 years agorelease-1.19.3 tag
Maxim Dounin [Tue, 29 Sep 2020 14:32:10 +0000 (17:32 +0300)]
release-1.19.3 tag

5 years agonginx-1.19.3-RELEASE release-1.19.3
Maxim Dounin [Tue, 29 Sep 2020 14:32:10 +0000 (17:32 +0300)]
nginx-1.19.3-RELEASE

5 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 29 Sep 2020 12:56:16 +0000 (15:56 +0300)]
Updated OpenSSL used for win32 builds.

5 years agoProxy: error checking for array init, missed in 7716:d6a5e14aa3e4.
Maxim Dounin [Tue, 29 Sep 2020 12:54:09 +0000 (15:54 +0300)]
Proxy: error checking for array init, missed in 7716:d6a5e14aa3e4.

Found by Coverity (CID 1467637).

5 years agoUserid: userid_flags fixup.
Maxim Dounin [Tue, 29 Sep 2020 12:52:18 +0000 (15:52 +0300)]
Userid: userid_flags fixup.

In 7717:e3e8b8234f05, the 1st bit was incorrectly used.  It shouldn't
be used for bitmask values, as it is used by NGX_CONF_BITMASK_SET.

Additionally, special value "off" added to make it possible to clear
inherited userid_flags value.

5 years agoResolver: improved error messages (ticket #2024).
Maxim Dounin [Mon, 28 Sep 2020 14:41:22 +0000 (17:41 +0300)]
Resolver: improved error messages (ticket #2024).

5 years agoUserid: userid_flags directive to set cookie flags.
Maxim Dounin [Mon, 28 Sep 2020 14:07:48 +0000 (17:07 +0300)]
Userid: userid_flags directive to set cookie flags.

5 years agoProxy: added the "proxy_cookie_flags" directive.
Ruslan Ermilov [Sun, 27 Sep 2020 20:21:11 +0000 (23:21 +0300)]
Proxy: added the "proxy_cookie_flags" directive.

5 years agoProxy: changed interface of some internal functions.
Ruslan Ermilov [Sun, 27 Sep 2020 20:21:10 +0000 (23:21 +0300)]
Proxy: changed interface of some internal functions.

This is in preparation for the next change.

Also, moved optimization from ngx_http_proxy_rewrite_regex_handler()
to ngx_http_proxy_rewrite().

5 years agoProxy: strengthen syntax checking for some directives.
Ruslan Ermilov [Sun, 27 Sep 2020 20:21:09 +0000 (23:21 +0300)]
Proxy: strengthen syntax checking for some directives.

The "false" parameter of the proxy_redirect directive is deprecated.
Warning has been emitted since c2230102df6f (0.7.54).

The "off" parameter of the proxy_redirect, proxy_cookie_domain, and
proxy_cookie_path directives tells nginx not to inherit the
configuration from the previous configuration level.

Previously, after specifying the directive with the "off" parameter,
any other directives were ignored, and syntax checking was disabled.

The syntax was enforced to allow either one directive with the "off"
parameter, or several directives with other parameters.

Also, specifying "proxy_redirect default foo" no longer works like
"proxy_redirect default".

5 years agoStream: set module.
Pavel Pautov [Fri, 28 Aug 2020 21:10:54 +0000 (14:10 -0700)]
Stream: set module.

Adds 'set' directive to the stream server context.

5 years agoSSL: abort handshake on SSL_set_SSL_CTX() errors.
Sergey Kandaurov [Thu, 24 Sep 2020 12:51:29 +0000 (13:51 +0100)]
SSL: abort handshake on SSL_set_SSL_CTX() errors.

In rare cases, such as memory allocation failure, SSL_set_SSL_CTX() returns
NULL, which could mean that a different SSL configuration has not been set.
Note that this new behaviour seemingly originated in OpenSSL-1.1.0 release.

5 years agoHTTP/2: run posted requests after reading body.
Maxim Dounin [Wed, 23 Sep 2020 16:52:31 +0000 (19:52 +0300)]
HTTP/2: run posted requests after reading body.

HTTP/2 code failed to run posted requests after calling the request body
handler, and this resulted in connection hang if a subrequest was created
in the body handler and no other actions were made.

5 years agoHTTP/2: fixed segfault on DATA frames after 400 errors.
Maxim Dounin [Wed, 23 Sep 2020 16:50:49 +0000 (19:50 +0300)]
HTTP/2: fixed segfault on DATA frames after 400 errors.

If 400 errors were redirected to an upstream server using the error_page
directive, DATA frames from the client might cause segmentation fault
due to null pointer dereference.  The bug had appeared in 6989:2c4dbcd6f2e4
(1.13.0).

Fix is to skip such frames in ngx_http_v2_state_read_data() (similarly
to 7561:9f1f9d6e056a).  With the fix, behaviour of 400 errors in HTTP/2
is now similar to one in HTTP/1.x, that is, nginx doesn't try to read the
request body.

Note that proxying 400 errors, as well as other early stage errors, to
upstream servers might not be a good idea anyway.  These errors imply
that reading and processing of the request (and the request headers)
wasn't complete, and proxying of such incomplete request might lead to
various errors.

Reported by Chenglong Zhang.

5 years agoSSL: disabled shutdown when there are buffered data.
Maxim Dounin [Wed, 16 Sep 2020 15:26:25 +0000 (18:26 +0300)]
SSL: disabled shutdown when there are buffered data.

This fixes "SSL_shutdown() failed (SSL: ... bad write retry)" errors
as observed on the second SSL_shutdown() call after SSL shutdown fixes in
09fb2135a589 (1.19.2), notably when HTTP/2 connections are closed due
to read timeouts while there are incomplete writes.

5 years agoSSL: disabled shutdown after connection errors.
Maxim Dounin [Wed, 16 Sep 2020 15:26:24 +0000 (18:26 +0300)]
SSL: disabled shutdown after connection errors.

This fixes "SSL_shutdown() failed (SSL: ... bad write retry)" errors
as observed on the second SSL_shutdown() call after SSL shutdown fixes in
09fb2135a589 (1.19.2), notably when sending fails in ngx_http_test_expect(),
similarly to ticket #1194.

Note that there are some places where c->error is misused to prevent
further output, such as ngx_http_v2_finalize_connection() if there
are pending streams, or in filter finalization.  These places seem
to be extreme enough to don't care about missing shutdown though.
For example, filter finalization currently prevents keepalive from
being used.

5 years agoSSL: fixed event handling during shutdown.
Maxim Dounin [Wed, 16 Sep 2020 15:26:23 +0000 (18:26 +0300)]
SSL: fixed event handling during shutdown.

The c->read->ready and c->write->ready flags need to be cleared to ensure
that appropriate read or write events will be reported by kernel.  Without
this, SSL shutdown might wait till the timeout after blocking on writing
or reading even if there is a socket activity.

5 years agoSSL: workaround for incorrect SSL_write() errors in OpenSSL 1.1.1.
Maxim Dounin [Wed, 16 Sep 2020 15:26:22 +0000 (18:26 +0300)]
SSL: workaround for incorrect SSL_write() errors in OpenSSL 1.1.1.

OpenSSL 1.1.1 fails to return SSL_ERROR_SYSCALL if an error happens
during SSL_write() after close_notify alert from the peer, and returns
SSL_ERROR_ZERO_RETURN instead.  Broken by this commit, which removes
the "i == 0" check around the SSL_RECEIVED_SHUTDOWN one:

https://git.openssl.org/?p=openssl.git;a=commitdiff;h=8051ab2

In particular, if a client closed the connection without reading
the response but with properly sent close_notify alert, this resulted in
unexpected "SSL_write() failed while ..." critical log message instead
of correct "SSL_write() failed (32: Broken pipe)" at the info level.

Since SSL_ERROR_ZERO_RETURN cannot be legitimately returned after
SSL_write(), the fix is to convert all SSL_ERROR_ZERO_RETURN errors
after SSL_write() to SSL_ERROR_SYSCALL.

5 years agoCache: keep c->body_start when Vary changes (ticket #2029).
Sergey Kandaurov [Wed, 9 Sep 2020 16:26:27 +0000 (19:26 +0300)]
Cache: keep c->body_start when Vary changes (ticket #2029).

If the variant hash doesn't match one we used as a secondary cache key,
we switch back to the original key.  In this case, c->body_start was kept
updated from an existing cache node overwriting the new response value.
After file cache update, it led to discrepancy between a cache node and
cache file seen as critical errors "file cache .. has too long header".

8 years agoCache: reset c->body_start when reading a variant on Vary mismatch.
Sergey Kandaurov [Fri, 4 Aug 2017 16:37:37 +0000 (19:37 +0300)]
Cache: reset c->body_start when reading a variant on Vary mismatch.

Previously, a variant not present in shared memory and stored on disk using a
secondary key was read using c->body_start from a variant stored with a main
key.  This could result in critical errors "cache file .. has too long header".

5 years agoHTTP/2: rejecting invalid stream identifiers with PROTOCOL_ERROR.
Sergey Kandaurov [Wed, 2 Sep 2020 20:13:36 +0000 (23:13 +0300)]
HTTP/2: rejecting invalid stream identifiers with PROTOCOL_ERROR.

Prodded by Xu Yang.

5 years agoCache: ignore stale-if-error for 4xx and 5xx codes.
Roman Arutyunyan [Wed, 29 Jul 2020 10:28:04 +0000 (13:28 +0300)]
Cache: ignore stale-if-error for 4xx and 5xx codes.

Previously the stale-if-error extension of the Cache-Control upstream header
triggered the return of a stale response for all error conditions that can be
specified in the proxy_cache_use_stale directive.  The list of these errors
includes both network/timeout/format errors, as well as some HTTP codes like
503, 504, 403, 429 etc.  The latter prevented a cache entry from being updated
by a response with any of these HTTP codes during the stale-if-error period.

Now stale-if-error only works for network/timeout/format errors and ignores
the upstream HTTP code.  The return of a stale response for certain HTTP codes
is still possible using the proxy_cache_use_stale directive.

This change also applies to the stale-while-revalidate extension of the
Cache-Control header, which triggers stale-if-error if it is missing.

Reported at
http://mailman.nginx.org/pipermail/nginx/2020-July/059723.html.

5 years agoVersion bump.
Roman Arutyunyan [Fri, 14 Aug 2020 09:45:52 +0000 (12:45 +0300)]
Version bump.

5 years agorelease-1.19.2 tag
Maxim Dounin [Tue, 11 Aug 2020 14:52:30 +0000 (17:52 +0300)]
release-1.19.2 tag

5 years agonginx-1.19.2-RELEASE release-1.19.2
Maxim Dounin [Tue, 11 Aug 2020 14:52:30 +0000 (17:52 +0300)]
nginx-1.19.2-RELEASE

5 years agoCore: reusing connections in advance.
Maxim Dounin [Mon, 10 Aug 2020 15:53:07 +0000 (18:53 +0300)]
Core: reusing connections in advance.

Reworked connections reuse, so closing connections is attempted in
advance, as long as number of free connections is less than 1/16 of
worker connections configured.  This ensures that new connections can
be handled even if closing a reusable connection requires some time,
for example, for a lingering close (ticket #2017).

The 1/16 ratio is selected to be smaller than 1/8 used for disabling
accept when working with accept mutex, so nginx will try to balance
new connections to different workers first, and will start reusing
connections only if this won't help.

5 years agoCore: added a warning about reusing connections.
Maxim Dounin [Mon, 10 Aug 2020 15:52:59 +0000 (18:52 +0300)]
Core: added a warning about reusing connections.

Previously, reusing connections happened silently and was only
visible in monitoring systems.  This was shown to be not very user-friendly,
and administrators often didn't realize there were too few connections
available to withstand the load, and configured timeouts (keepalive_timeout
and http2_idle_timeout) were effectively reduced to keep things running.

To provide at least some information about this, a warning is now logged
(at most once per second, to avoid flooding the logs).

5 years agoSSL: disabled sending shutdown after ngx_http_test_reading().
Maxim Dounin [Mon, 10 Aug 2020 15:52:34 +0000 (18:52 +0300)]
SSL: disabled sending shutdown after ngx_http_test_reading().

Sending shutdown when ngx_http_test_reading() detects the connection is
closed can result in "SSL_shutdown() failed (SSL: ... bad write retry)"
critical log messages if there are blocked writes.

Fix is to avoid sending shutdown via the c->ssl->no_send_shutdown flag,
similarly to how it is done in ngx_http_keepalive_handler() for kqueue
when pending EOF is detected.

Reported by Jan Prachaƙ
(http://mailman.nginx.org/pipermail/nginx-devel/2018-December/011702.html).

5 years agoHTTP/2: fixed c->timedout flag on timed out connections.
Maxim Dounin [Mon, 10 Aug 2020 15:52:20 +0000 (18:52 +0300)]
HTTP/2: fixed c->timedout flag on timed out connections.

Without the flag, SSL shutdown is attempted on such connections,
resulting in useless work and/or bogus "SSL_shutdown() failed
(SSL: ... bad write retry)" critical log messages if there are
blocked writes.

5 years agoSSL: fixed shutdown handling.
Maxim Dounin [Mon, 10 Aug 2020 15:52:09 +0000 (18:52 +0300)]
SSL: fixed shutdown handling.

Previously, bidirectional shutdown never worked, due to two issues
in the code:

1. The code only tested SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE
   when there was an error in the error queue, which cannot happen.
   The bug was introduced in an attempt to fix unexpected error logging
   as reported with OpenSSL 0.9.8g
   (http://mailman.nginx.org/pipermail/nginx/2008-January/003084.html).

2. The code never called SSL_shutdown() for the second time to wait for
   the peer's close_notify alert.

This change fixes both issues.

Note that after this change bidirectional shutdown is expected to work for
the first time, so c->ssl->no_wait_shutdown now makes a difference.  This
is not a problem for HTTP code which always uses c->ssl->no_wait_shutdown,
but might be a problem for stream and mail code, as well as 3rd party
modules.

To minimize the effect of the change, the timeout, which was used to be 30
seconds and not configurable, though never actually used, is now set to
3 seconds.  It is also expanded to apply to both SSL_ERROR_WANT_READ and
SSL_ERROR_WANT_WRITE, so timeout is properly set if writing to the socket
buffer is not possible.

5 years agoRequest body: optimized handling of small chunks.
Maxim Dounin [Thu, 6 Aug 2020 02:02:57 +0000 (05:02 +0300)]
Request body: optimized handling of small chunks.

If there is a previous buffer, copy small chunks into it instead of
allocating additional buffer.

5 years agoRequest body: allowed large reads on chunk boundaries.
Maxim Dounin [Thu, 6 Aug 2020 02:02:55 +0000 (05:02 +0300)]
Request body: allowed large reads on chunk boundaries.

If some additional data from a pipelined request happens to be
read into the body buffer, we copy it to r->header_in or allocate
an additional large client header buffer for it.

5 years agoRequest body: all read data are now sent to filters.
Maxim Dounin [Thu, 6 Aug 2020 02:02:44 +0000 (05:02 +0300)]
Request body: all read data are now sent to filters.

This is a prerequisite for the next change to allow large reads
on chunk boundaries.

5 years agoAdded size check to ngx_http_alloc_large_header_buffer().
Maxim Dounin [Thu, 6 Aug 2020 02:02:22 +0000 (05:02 +0300)]
Added size check to ngx_http_alloc_large_header_buffer().

This ensures that copying won't write more than the buffer size
even if the buffer comes from hc->free and it is smaller than the large
client header buffer size in the virtual host configuration.  This might
happen if size of large client header buffers is different in name-based
virtual hosts, similarly to the problem with number of buffers fixed
in 6926:e662cbf1b932.

5 years agoFastCGI: fixed zero size buf alerts on extra data (ticket #2018).
Maxim Dounin [Mon, 27 Jul 2020 13:02:15 +0000 (16:02 +0300)]
FastCGI: fixed zero size buf alerts on extra data (ticket #2018).

After 05e42236e95b (1.19.1) responses with extra data might result in
zero size buffers being generated and "zero size buf" alerts in writer
(if f->rest happened to be 0 when processing additional stdout data).

5 years agoCore: enclosed parameters of the ngx_buf.h macros in parentheses.
balus [Mon, 27 Jul 2020 10:21:51 +0000 (13:21 +0300)]
Core: enclosed parameters of the ngx_buf.h macros in parentheses.

5 years agoOCSP: fixed certificate reference leak.
Sergey Kandaurov [Thu, 23 Jul 2020 14:31:09 +0000 (17:31 +0300)]
OCSP: fixed certificate reference leak.

5 years agoXslt: disabled ranges.
Roman Arutyunyan [Wed, 22 Jul 2020 19:16:19 +0000 (22:16 +0300)]
Xslt: disabled ranges.

Previously, the document generated by the xslt filter was always fully sent
to client even if a range was requested and response status was 206 with
appropriate Content-Range.

The xslt module is unable to serve a range because of suspending the header
filter chain.  By the moment full response xml is buffered by the xslt filter,
range header filter is not called yet, but the range body filter has already
been called and did nothing.

The fix is to disable ranges by resetting the r->allow_ranges flag much like
the image filter that employs a similar technique.

5 years agoCore: close PID file when writing fails.
Ruslan Ermilov [Tue, 21 Jul 2020 17:34:29 +0000 (20:34 +0300)]
Core: close PID file when writing fails.

Reported by Jinhua Tan.

5 years agoSlice filter: clear original Accept-Ranges.
Roman Arutyunyan [Thu, 9 Jul 2020 13:21:37 +0000 (16:21 +0300)]
Slice filter: clear original Accept-Ranges.

The slice filter allows ranges for the response by setting the r->allow_ranges
flag, which enables the range filter.  If the range was not requested, the
range filter adds an Accept-Ranges header to the response to signal the
support for ranges.

Previously, if an Accept-Ranges header was already present in the first slice
response, client received two copies of this header.  Now, the slice filter
removes the Accept-Ranges header from the response prior to setting the
r->allow_ranges flag.

5 years agoVersion bump.
Roman Arutyunyan [Thu, 9 Jul 2020 14:33:22 +0000 (17:33 +0300)]
Version bump.

5 years agorelease-1.19.1 tag
Maxim Dounin [Tue, 7 Jul 2020 15:56:06 +0000 (18:56 +0300)]
release-1.19.1 tag

5 years agonginx-1.19.1-RELEASE release-1.19.1
Maxim Dounin [Tue, 7 Jul 2020 15:56:05 +0000 (18:56 +0300)]
nginx-1.19.1-RELEASE

5 years agogRPC: generate error when response size is wrong.
Maxim Dounin [Mon, 6 Jul 2020 15:36:25 +0000 (18:36 +0300)]
gRPC: generate error when response size is wrong.

As long as the "Content-Length" header is given, we now make sure
it exactly matches the size of the response.  If it doesn't,
the response is considered malformed and must not be forwarded
(https://tools.ietf.org/html/rfc7540#section-8.1.2.6).  While it
is not really possible to "not forward" the response which is already
being forwarded, we generate an error instead, which is the closest
equivalent.

Previous behaviour was to pass everything to the client, but this
seems to be suboptimal and causes issues (ticket #1695).  Also this
directly contradicts HTTP/2 specification requirements.

Note that the new behaviour for the gRPC proxy is more strict than that
applied in other variants of proxying.  This is intentional, as HTTP/2
specification requires us to do so, while in other types of proxying
malformed responses from backends are well known and historically
tolerated.

5 years agoFastCGI: protection from responses with wrong length.
Maxim Dounin [Mon, 6 Jul 2020 15:36:23 +0000 (18:36 +0300)]
FastCGI: protection from responses with wrong length.

Previous behaviour was to pass everything to the client, but this
seems to be suboptimal and causes issues (ticket #1695).  Fix is to
drop extra data instead, as it naturally happens in most clients.

Additionally, we now also issue a warning if the response is too
short, and make sure the fact it is truncated is propagated to the
client.  The u->error flag is introduced to make it possible to
propagate the error to the client in case of unbuffered proxying.

For responses to HEAD requests there is an exception: we do allow
both responses without body and responses with body matching the
Content-Length header.

5 years agoUpstream: drop extra data sent by upstream.
Maxim Dounin [Mon, 6 Jul 2020 15:36:22 +0000 (18:36 +0300)]
Upstream: drop extra data sent by upstream.

Previous behaviour was to pass everything to the client, but this
seems to be suboptimal and causes issues (ticket #1695).  Fix is to
drop extra data instead, as it naturally happens in most clients.

This change covers generic buffered and unbuffered filters as used
in the scgi and uwsgi modules.  Appropriate input filter init
handlers are provided by the scgi and uwsgi modules to set corresponding
lengths.

Note that for responses to HEAD requests there is an exception:
we do allow any response length.  This is because responses to HEAD
requests might be actual full responses, and it is up to nginx
to remove the response body.  If caching is enabled, only full
responses matching the Content-Length header will be cached
(see b779728b180c).

5 years agoProxy: style.
Maxim Dounin [Mon, 6 Jul 2020 15:36:21 +0000 (18:36 +0300)]
Proxy: style.

5 years agoProxy: detection of data after final chunk.
Maxim Dounin [Mon, 6 Jul 2020 15:36:20 +0000 (18:36 +0300)]
Proxy: detection of data after final chunk.

Previously, additional data after final chunk was either ignored
(in the same buffer, or during unbuffered proxying) or sent to the
client (in the next buffer already if it was already read from the
socket).  Now additional data are properly detected and ignored
in all cases.  Additionally, a warning is now logged and keepalive
is disabled in the connection.

5 years agoProxy: drop extra data sent by upstream.
Maxim Dounin [Mon, 6 Jul 2020 15:36:19 +0000 (18:36 +0300)]
Proxy: drop extra data sent by upstream.

Previous behaviour was to pass everything to the client, but this
seems to be suboptimal and causes issues (ticket #1695).  Fix is to
drop extra data instead, as it naturally happens in most clients.

5 years agoMemcached: protect from too long responses.
Maxim Dounin [Mon, 6 Jul 2020 15:36:17 +0000 (18:36 +0300)]
Memcached: protect from too long responses.

If a memcached response was followed by a correct trailer, and then
the NUL character followed by some extra data - this was accepted by
the trailer checking code.  This in turn resulted in ctx->rest underflow
and caused negative size buffer on the next reading from the upstream,
followed by the "negative size buf in writer" alert.

Fix is to always check for too long responses, so a correct trailer cannot
be followed by extra data.

5 years agoHTTP/2: lingering close after GOAWAY.
Ruslan Ermilov [Fri, 3 Jul 2020 13:16:47 +0000 (16:16 +0300)]
HTTP/2: lingering close after GOAWAY.

After sending the GOAWAY frame, a connection is now closed using
the lingering close mechanism.

This allows for the reliable delivery of the GOAWAY frames, while
also fixing connection resets observed when http2_max_requests is
reached (ticket #1250), or with graceful shutdown (ticket #1544),
when some additional data from the client is received on a fully
closed connection.

For HTTP/2, the settings lingering_close, lingering_timeout, and
lingering_time are taken from the "server" level.

5 years agoSSL: fixed unexpected certificate requests (ticket #2008).
Maxim Dounin [Mon, 29 Jun 2020 14:15:51 +0000 (17:15 +0300)]
SSL: fixed unexpected certificate requests (ticket #2008).

Using SSL_CTX_set_verify(SSL_VERIFY_PEER) implies that OpenSSL will
send a certificate request during an SSL handshake, leading to unexpected
certificate requests from browsers as long as there are any client
certificates installed.  Given that ngx_ssl_trusted_certificate()
is called unconditionally by the ngx_http_ssl_module, this affected
all HTTPS servers.  Broken by 699f6e55bbb4 (not released yet).

Fix is to set verify callback in the ngx_ssl_trusted_certificate() function
without changing the verify mode.