]> git.kaiwu.me - nginx.git/log
nginx.git
9 years agoHTTP/2: fixed a segfault while processing unbuffered upload.
Valentin Bartenev [Thu, 16 Jun 2016 17:55:11 +0000 (20:55 +0300)]
HTTP/2: fixed a segfault while processing unbuffered upload.

The ngx_http_v2_finalize_connection() closes current stream, but that is an
invalid operation while processing unbuffered upload.  This results in access
to already freed memory, since the upstream module sets a cleanup handler that
also finalizes the request.

9 years agoHTTP/2: unbreak build on MSVC.
Valentin Bartenev [Tue, 24 May 2016 18:54:32 +0000 (21:54 +0300)]
HTTP/2: unbreak build on MSVC.

9 years agoHTTP/2: implemented preread buffer for request body (closes #959).
Valentin Bartenev [Tue, 24 May 2016 14:37:52 +0000 (17:37 +0300)]
HTTP/2: implemented preread buffer for request body (closes #959).

Previously, the stream's window was kept zero in order to prevent a client
from sending the request body before it was requested (see 887cca40ba6a for
details).  Until such initial window was acknowledged all requests with
data were rejected (see 0aa07850922f for details).

That approach revealed a number of problems:

 1. Some clients (notably MS IE/Edge, Safari, iOS applications) show an error
    or even crash if a stream is rejected;

 2. This requires at least one RTT for every request with body before the
    client receives window update and able to send data.

To overcome these problems the new directive "http2_body_preread_size" is
introduced.  It sets the initial window and configures a special per stream
preread buffer that is used to save all incoming data before the body is
requested and processed.

If the directive's value is lower than the default initial window (65535),
as previously, all streams with data will be rejected until the new window
is acknowledged.  Otherwise, no special processing is used and all requests
with data are welcome right from the connection start.

The default value is chosen to be 64k, which is bigger than the default
initial window.  Setting it to zero is fully complaint to the previous
behavior.

9 years agoHTTP/2: the "421 Misdirected Request" response (closes #848).
Valentin Bartenev [Fri, 20 May 2016 15:41:17 +0000 (18:41 +0300)]
HTTP/2: the "421 Misdirected Request" response (closes #848).

Since 4fbef397c753 nginx rejects with the 400 error any attempts of
requesting different host over the same connection, if the relevant
virtual server requires verification of a client certificate.

While requesting hosts other than negotiated isn't something legal
in HTTP/1.x, the HTTP/2 specification explicitly permits such requests
for connection reuse and has introduced a special response code 421.

According to RFC 7540 Section 9.1.2 this code can be sent by a server
that is not configured to produce responses for the combination of
scheme and authority that are included in the request URI.  And the
client may retry the request over a different connection.

Now this code is used for requests that aren't authorized in current
connection.  After receiving the 421 response a client will be able
to open a new connection, provide the required certificate and retry
the request.

Unfortunately, not all clients currently are able to handle it well.
Notably Chrome just shows an error, while at least the latest version
of Firefox retries the request over a new connection.

9 years agoVersion bump.
Maxim Dounin [Tue, 18 Oct 2016 14:19:51 +0000 (17:19 +0300)]
Version bump.

9 years agorelease-1.10.1 tag
Maxim Dounin [Tue, 31 May 2016 13:47:01 +0000 (16:47 +0300)]
release-1.10.1 tag

9 years agonginx-1.10.1-RELEASE release-1.10.1
Maxim Dounin [Tue, 31 May 2016 13:47:01 +0000 (16:47 +0300)]
nginx-1.10.1-RELEASE

9 years agoCore: skip special buffers on writing (ticket #981).
Maxim Dounin [Tue, 31 May 2016 02:13:30 +0000 (05:13 +0300)]
Core: skip special buffers on writing (ticket #981).

A special last buffer with cl->buf->pos set to NULL can be present in
a chain when writing request body if chunked encoding was used.  This
resulted in a NULL pointer dereference if it happened to be the only
buffer left after a do...while loop iteration in ngx_write_chain_to_file().

The problem originally appeared in nginx 1.3.9 with chunked encoding
support.  Additionally, rev. 3832b608dc8d (nginx 1.9.13) changed the
minimum number of buffers to trigger this from IOV_MAX (typically 1024)
to NGX_IOVS_PREALLOCATE (typically 64).

Fix is to skip such buffers in ngx_chain_to_iovec(), much like it is
done in other places.

9 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 24 May 2016 14:44:01 +0000 (17:44 +0300)]
Updated OpenSSL used for win32 builds.

9 years agoVersion bump.
Maxim Dounin [Mon, 30 May 2016 23:21:38 +0000 (02:21 +0300)]
Version bump.

10 years agorelease-1.10.0 tag
Maxim Dounin [Tue, 26 Apr 2016 13:31:18 +0000 (16:31 +0300)]
release-1.10.0 tag

10 years agonginx-1.10.0-RELEASE release-1.10.0
Maxim Dounin [Tue, 26 Apr 2016 13:31:18 +0000 (16:31 +0300)]
nginx-1.10.0-RELEASE

10 years agoStable branch.
Maxim Dounin [Tue, 26 Apr 2016 13:30:30 +0000 (16:30 +0300)]
Stable branch.

10 years agorelease-1.9.15 tag
Maxim Dounin [Tue, 19 Apr 2016 16:02:37 +0000 (19:02 +0300)]
release-1.9.15 tag

10 years agonginx-1.9.15-RELEASE release-1.9.15
Maxim Dounin [Tue, 19 Apr 2016 16:02:37 +0000 (19:02 +0300)]
nginx-1.9.15-RELEASE

10 years agoHTTP/2: send the output queue after emitting WINDOW_UPDATE.
Valentin Bartenev [Tue, 19 Apr 2016 14:38:49 +0000 (17:38 +0300)]
HTTP/2: send the output queue after emitting WINDOW_UPDATE.

The WINDOW_UPDATE frame could be left in the output queue for an indefinite
period of time resulting in the request timeout.

This might happen if reading of the body was triggered by an event unrelated
to client connection, e.g. by the limit_req timer.

10 years agoHTTP/2: skip data frames in case of internal errors.
Valentin Bartenev [Tue, 19 Apr 2016 14:38:49 +0000 (17:38 +0300)]
HTTP/2: skip data frames in case of internal errors.

This prevents possible processing of such frames and triggering
rb->post_handler if an error occurred during r->request_body
initialization.

10 years agoHTTP/2: don't send WINDOW_UPDATE for an empty request body.
Valentin Bartenev [Tue, 19 Apr 2016 14:38:49 +0000 (17:38 +0300)]
HTTP/2: don't send WINDOW_UPDATE for an empty request body.

Particularly this prevents sending WINDOW_UPDATE with zero delta
which can result in PROTOCOL_ERROR.

Also removed surplus setting of no_flow_control to 0.

10 years agoThread pools: memory barriers in task completion notifications.
Maxim Dounin [Tue, 19 Apr 2016 14:18:28 +0000 (17:18 +0300)]
Thread pools: memory barriers in task completion notifications.

The ngx_thread_pool_done object isn't volatile, and at least some
compilers assume that it is permitted to reorder modifications of
volatile and non-volatile objects.  Added appropriate ngx_memory_barrier()
calls to make sure all modifications will happen before the lock is released.

Reported by Mindaugas Rasiukevicius,
http://mailman.nginx.org/pipermail/nginx-devel/2016-April/008160.html.

10 years agoHTTP/2: write logs when refusing streams with data.
Maxim Dounin [Mon, 18 Apr 2016 18:18:24 +0000 (21:18 +0300)]
HTTP/2: write logs when refusing streams with data.

Refusing streams is known to be incorrectly handled at least by IE, Edge
and Safari.  Make sure to provide appropriate logging to simplify fixing
this in the affected browsers.

10 years agoHTTP/2: send WINDOW_UPDATE instead of RST_STREAM with NO_ERROR.
Valentin Bartenev [Thu, 14 Apr 2016 12:14:15 +0000 (15:14 +0300)]
HTTP/2: send WINDOW_UPDATE instead of RST_STREAM with NO_ERROR.

After the 92464ebace8e change, it has been discovered that not all
clients follow the RFC and handle RST_STREAM with NO_ERROR properly.

Notably, Chrome currently interprets it as INTERNAL_ERROR and discards
the response.

As a workaround, instead of RST_STREAM the maximum stream window update
will be sent, which will let client to send up to 2 GB of a request body
data before getting stuck on flow control.  All the received data will
be silently discarded.

See for details:
http://mailman.nginx.org/pipermail/nginx-devel/2016-April/008143.html
https://bugs.chromium.org/p/chromium/issues/detail?id=603182

10 years agoHTTP/2: refuse streams with data until SETTINGS is acknowledged.
Valentin Bartenev [Thu, 14 Apr 2016 12:14:15 +0000 (15:14 +0300)]
HTTP/2: refuse streams with data until SETTINGS is acknowledged.

A client is allowed to send requests before receiving and acknowledging
the SETTINGS frame.  Such a client having a wrong idea about the stream's
could send the request body that nginx isn't ready to process.

The previous behavior was to send RST_STREAM with FLOW_CONTROL_ERROR in
such case, but it didn't allow retrying requests that have been rejected.

10 years agoHTTP/2: deduplicated some code in ngx_http_v2_state_headers().
Valentin Bartenev [Thu, 14 Apr 2016 12:14:15 +0000 (15:14 +0300)]
HTTP/2: deduplicated some code in ngx_http_v2_state_headers().

No functional changes.

10 years agoFastCGI: skip special bufs in buffered request body chain.
Valentin Bartenev [Mon, 11 Apr 2016 15:42:34 +0000 (18:42 +0300)]
FastCGI: skip special bufs in buffered request body chain.

This prevents forming empty records out of such buffers.  Particularly it fixes
double end-of-stream records with chunked transfer encoding, or when HTTP/2 is
used and the END_STREAM flag has been sent without data.  In both cases there
is an empty buffer at the end of the request body chain with the "last_buf"
flag set.

The canonical libfcgi, as well as php implementation, tolerates such records,
while the HHVM parser is more strict and drops the connection (ticket #950).

10 years agoFixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse (as in e444e8f6538b).
Ruslan Ermilov [Tue, 12 Apr 2016 16:01:56 +0000 (19:01 +0300)]
Fixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse (as in e444e8f6538b).

10 years agoFixed typos.
Alessandro Ghedini [Mon, 11 Apr 2016 15:47:11 +0000 (16:47 +0100)]
Fixed typos.

10 years agoRemoved redundant "u" format specifier.
Ruslan Ermilov [Fri, 8 Apr 2016 12:03:38 +0000 (15:03 +0300)]
Removed redundant "u" format specifier.

It is implied for "x" and "X".

10 years agoSimplified ngx_unix_recv() and ngx_readv_chain().
Ruslan Ermilov [Fri, 8 Apr 2016 13:49:35 +0000 (16:49 +0300)]
Simplified ngx_unix_recv() and ngx_readv_chain().

This makes ngx_unix_recv() and ngx_udp_unix_recv() differ minimally.

10 years agoMerged implementations of ngx_unix_recv().
Valentin Bartenev [Fri, 8 Apr 2016 13:41:45 +0000 (16:41 +0300)]
Merged implementations of ngx_unix_recv().

There's no real need in two separate implementations,
with and without kqueue support.

10 years agoFixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev [Fri, 8 Apr 2016 13:39:49 +0000 (16:39 +0300)]
Fixed small inconsistency in handling EOF among receive functions.

Now all functions always drop the ready flag in this case.

10 years agoMerged implementations of ngx_udp_unix_recv().
Valentin Bartenev [Fri, 8 Apr 2016 13:38:42 +0000 (16:38 +0300)]
Merged implementations of ngx_udp_unix_recv().

There's no real need in two separate implementations,
with and without kqueue support.

10 years agoFixed spelling.
Josh Soref [Thu, 7 Apr 2016 08:50:13 +0000 (11:50 +0300)]
Fixed spelling.

10 years agoVersion bump.
Ruslan Ermilov [Thu, 7 Apr 2016 16:09:42 +0000 (19:09 +0300)]
Version bump.

10 years agorelease-1.9.14 tag
Maxim Dounin [Tue, 5 Apr 2016 14:57:08 +0000 (17:57 +0300)]
release-1.9.14 tag

10 years agonginx-1.9.14-RELEASE release-1.9.14
Maxim Dounin [Tue, 5 Apr 2016 14:57:08 +0000 (17:57 +0300)]
nginx-1.9.14-RELEASE

10 years agoCompatibility with FreeBSD 2.2.9.
Maxim Dounin [Fri, 1 Apr 2016 13:38:31 +0000 (16:38 +0300)]
Compatibility with FreeBSD 2.2.9.

Added (RTLD_NOW | RTLD_GLOBAL) to dlopen() test.  There is no RTLD_GLOBAL
on FreeBSD 2.2.9.

Added uint32_t test, with fallback to u_int32_t, similar to uint64_t one.
Added fallback to u_int32_t in in_addr_t test.

With these changes it is now possible to compile nginx on FreeBSD 2.2.9
with only few minor warnings (assuming -Wno-error).

10 years agoConfigure: improved multiple types handling in auto/types/typedef.
Maxim Dounin [Fri, 1 Apr 2016 13:38:30 +0000 (16:38 +0300)]
Configure: improved multiple types handling in auto/types/typedef.

10 years agoConfigure: fixed autotest source code logging.
Maxim Dounin [Fri, 1 Apr 2016 13:38:28 +0000 (16:38 +0300)]
Configure: fixed autotest source code logging.

Fixed a regression introduced in rev. 434548349838 that prevented
auto/types/sizeof and auto/types/typedef properly reporting autotest
source code to autoconf.err in case of test failure.

10 years agoHTTP/2: support for unbuffered upload of request body.
Valentin Bartenev [Fri, 1 Apr 2016 12:57:10 +0000 (15:57 +0300)]
HTTP/2: support for unbuffered upload of request body.

10 years agoHTTP/2: rewritten handling of request body.
Valentin Bartenev [Fri, 1 Apr 2016 12:56:03 +0000 (15:56 +0300)]
HTTP/2: rewritten handling of request body.

There are two improvements:

  1. Support for request body filters;

  2. Receiving of request body is started only after
     the ngx_http_read_client_request_body() call.

The last one fixes the problem when the client_max_body_size value might not be
respected from the right location if the location was changed either during the
process of receiving body or after the whole body had been received.

10 years agoHTTP/2: sending RST_STREAM with NO_ERROR to discard request body.
Valentin Bartenev [Fri, 1 Apr 2016 12:56:03 +0000 (15:56 +0300)]
HTTP/2: sending RST_STREAM with NO_ERROR to discard request body.

RFC 7540 states that "A server can send a complete response prior to the client
sending an entire request if the response does not depend on any portion of the
request that has not been sent and received.  When this is true, a server MAY
request that the client abort transmission of a request without error by sending
a RST_STREAM with an error code of NO_ERROR after sending a complete response
(i.e., a frame with the END_STREAM flag)."

This should prevent a client from blocking on the stream window, since it isn't
maintained for closed streams.  Currently, quite big initial stream windows are
used, so such blocking is very unlikly, but that will be changed in the further
patches.

10 years agoCore: removed incorrect GCC 2.7 check.
Maxim Dounin [Fri, 1 Apr 2016 10:17:12 +0000 (13:17 +0300)]
Core: removed incorrect GCC 2.7 check.

It was broken since introduction (__GNU__ instead of __GNUC__) and did
nothing.  Moreover, GCC 2.7 is happy with the normal version of the code.

Reported by Joel Cunningham,
http://mailman.nginx.org/pipermail/nginx-devel/2016-March/007964.html.

10 years agoTrailing space fix.
Maxim Dounin [Fri, 1 Apr 2016 01:17:00 +0000 (04:17 +0300)]
Trailing space fix.

10 years agoSSL: SSLeay_version() is deprecated in OpenSSL 1.1.0.
Maxim Dounin [Thu, 31 Mar 2016 20:38:38 +0000 (23:38 +0300)]
SSL: SSLeay_version() is deprecated in OpenSSL 1.1.0.

SSLeay_version() and SSLeay() are no longer available if OPENSSL_API_COMPAT
is set to 0x10100000L.  Switched to using OpenSSL_version() instead.

Additionally, we now compare version strings instead of version numbers,
and this correctly works for LibreSSL as well.

10 years agoSSL: X509 was made opaque in OpenSSL 1.1.0.
Sergey Kandaurov [Thu, 31 Mar 2016 20:38:37 +0000 (23:38 +0300)]
SSL: X509 was made opaque in OpenSSL 1.1.0.

To increment reference counters we now use newly introduced X509_up_ref()
function.

10 years agoSSL: EVP_MD_CTX was made opaque in OpenSSL 1.1.0.
Sergey Kandaurov [Thu, 31 Mar 2016 20:38:36 +0000 (23:38 +0300)]
SSL: EVP_MD_CTX was made opaque in OpenSSL 1.1.0.

10 years agoSSL: RSA_generate_key() is deprecated in OpenSSL 1.1.0.
Maxim Dounin [Thu, 31 Mar 2016 20:38:34 +0000 (23:38 +0300)]
SSL: RSA_generate_key() is deprecated in OpenSSL 1.1.0.

OpenSSL removed support for all 40 and 56 bit ciphers.

10 years agoSSL: initialization changes for OpenSSL 1.1.0.
Maxim Dounin [Thu, 31 Mar 2016 20:38:33 +0000 (23:38 +0300)]
SSL: initialization changes for OpenSSL 1.1.0.

OPENSSL_config() deprecated in OpenSSL 1.1.0.  Additionally,
SSL_library_init(), SSL_load_error_strings() and OpenSSL_add_all_algorithms()
are no longer available if OPENSSL_API_COMPAT is set to 0x10100000L.

The OPENSSL_init_ssl() function is now used instead with appropriate
arguments to trigger the same behaviour.  The configure test changed to
use SSL_CTX_set_options().

Deinitialization now happens automatically in OPENSSL_cleanup() called
via atexit(3), so we no longer call EVP_cleanup() and ENGINE_cleanup()
directly.

10 years agoSSL: get_session callback changed in OpenSSL 1.1.0.
Maxim Dounin [Thu, 31 Mar 2016 20:38:32 +0000 (23:38 +0300)]
SSL: get_session callback changed in OpenSSL 1.1.0.

10 years agoSSL: guarded error codes not present in OpenSSL 1.1.0.
Maxim Dounin [Thu, 31 Mar 2016 20:38:31 +0000 (23:38 +0300)]
SSL: guarded error codes not present in OpenSSL 1.1.0.

10 years agoSSL: reasonable version for LibreSSL.
Maxim Dounin [Thu, 31 Mar 2016 20:38:29 +0000 (23:38 +0300)]
SSL: reasonable version for LibreSSL.

LibreSSL defines OPENSSL_VERSION_NUMBER to 0x20000000L, but uses an old
API derived from OpenSSL at the time LibreSSL forked.  As a result, every
version check we use to test for new API elements in newer OpenSSL versions
requires an explicit check for LibreSSL.

To reduce clutter, redefine OPENSSL_VERSION_NUMBER to 0x1000107fL if
LibreSSL is used.  The same is done by FreeBSD port of LibreSSL.

10 years agoRemoved the prototype mysql module.
Ruslan Ermilov [Thu, 31 Mar 2016 19:33:26 +0000 (22:33 +0300)]
Removed the prototype mysql module.

10 years agoFixed ngx_os_signal_process() prototype.
Ruslan Ermilov [Thu, 31 Mar 2016 19:00:33 +0000 (22:00 +0300)]
Fixed ngx_os_signal_process() prototype.

10 years agoFixed ngx_pid_t formatting in ngx_sprintf() and logging.
Sergey Kandaurov [Wed, 30 Mar 2016 23:34:04 +0000 (02:34 +0300)]
Fixed ngx_pid_t formatting in ngx_sprintf() and logging.

10 years agoFixed format specifiers in ngx_sprintf().
Sergey Kandaurov [Wed, 30 Mar 2016 23:34:00 +0000 (02:34 +0300)]
Fixed format specifiers in ngx_sprintf().

10 years agoFixed logging.
Sergey Kandaurov [Wed, 30 Mar 2016 23:33:57 +0000 (02:33 +0300)]
Fixed logging.

10 years agoEvents: fixed logging.
Sergey Kandaurov [Wed, 30 Mar 2016 23:33:55 +0000 (02:33 +0300)]
Events: fixed logging.

10 years agoFixed logging with variable field width.
Sergey Kandaurov [Wed, 30 Mar 2016 23:33:53 +0000 (02:33 +0300)]
Fixed logging with variable field width.

10 years agoFixed logging in close error handling.
Sergey Kandaurov [Wed, 30 Mar 2016 23:33:50 +0000 (02:33 +0300)]
Fixed logging in close error handling.

10 years agoFixed mistranslated phrase.
Ruslan Ermilov [Wed, 30 Mar 2016 09:07:19 +0000 (12:07 +0300)]
Fixed mistranslated phrase.

10 years agoEvents: fixed test building with eventport on OS X.
Ruslan Ermilov [Wed, 30 Mar 2016 08:57:28 +0000 (11:57 +0300)]
Events: fixed test building with eventport on OS X.

Broken in d17f0584006f (1.9.13).

10 years agoStyle.
Ruslan Ermilov [Wed, 30 Mar 2016 08:52:16 +0000 (11:52 +0300)]
Style.

10 years agoVersion bump.
Ruslan Ermilov [Wed, 30 Mar 2016 08:52:07 +0000 (11:52 +0300)]
Version bump.

10 years agorelease-1.9.13 tag
Maxim Dounin [Tue, 29 Mar 2016 15:09:30 +0000 (18:09 +0300)]
release-1.9.13 tag

10 years agonginx-1.9.13-RELEASE release-1.9.13
Maxim Dounin [Tue, 29 Mar 2016 15:09:30 +0000 (18:09 +0300)]
nginx-1.9.13-RELEASE

10 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 29 Mar 2016 06:54:11 +0000 (09:54 +0300)]
Updated OpenSSL used for win32 builds.

10 years agoWin32: replaced NGX_EXDEV with more appropriate error code.
Maxim Dounin [Tue, 29 Mar 2016 06:52:15 +0000 (09:52 +0300)]
Win32: replaced NGX_EXDEV with more appropriate error code.

Correct error code for NGX_EXDEV on Windows is ERROR_NOT_SAME_DEVICE,
"The system cannot move the file to a different disk drive".

Previously used ERROR_WRONG_DISK is about wrong diskette in the drive and
is not appropriate.

There is no real difference though, as MoveFile() is able to copy files
between disk drives, and will fail with ERROR_ACCESS_DENIED when asked
to copy directories.  The ERROR_NOT_SAME_DEVICE error is only used
by MoveFileEx() when called without the MOVEFILE_COPY_ALLOWED flag.

10 years agoWin32: additional error code NGX_EEXIST_FILE (ticket #910).
Maxim Dounin [Tue, 29 Mar 2016 06:51:46 +0000 (09:51 +0300)]
Win32: additional error code NGX_EEXIST_FILE (ticket #910).

On Windows there are two possible error codes which correspond to
the EEXIST error code: ERROR_FILE_EXISTS used by CreateFile(CREATE_NEW),
and ERROR_ALREADY_EXISTS used by CreateDirectory().

MoveFile() seems to use both: ERROR_ALREADY_EXISTS when moving within
one filesystem, and ERROR_FILE_EXISTS when copying a file to a different
drive.

10 years agoUpstream: proxy_next_upstream non_idempotent.
Maxim Dounin [Mon, 28 Mar 2016 16:50:19 +0000 (19:50 +0300)]
Upstream: proxy_next_upstream non_idempotent.

By default, requests with non-idempotent methods (POST, LOCK, PATCH)
are no longer retried in case of errors if a request was already sent
to a backend.  Previous behaviour can be restored by using
"proxy_next_upstream ... non_idempotent".

10 years agoUpstream: cached connections now tested against next_upstream.
Maxim Dounin [Mon, 28 Mar 2016 16:49:52 +0000 (19:49 +0300)]
Upstream: cached connections now tested against next_upstream.

Much like normal connections, cached connections are now tested against
u->conf->next_upstream, and u->state->status is now always set.

This allows to disable additional tries even with upstream keepalive
by using "proxy_next_upstream off".

10 years agoFixed --test-build-*.
Ruslan Ermilov [Mon, 28 Mar 2016 16:29:18 +0000 (19:29 +0300)]
Fixed --test-build-*.

Fixes various aspects of --test-build-devpoll, --test-build-eventport, and
--test-build-epoll.

In particular, if --test-build-devpoll was used on Linux, then "devpoll"
event method would be preferred over "epoll".  Also, wrong definitions of
event macros were chosen.

10 years agoSub filter: fixed allocation alignment.
Roman Arutyunyan [Mon, 28 Mar 2016 10:35:25 +0000 (13:35 +0300)]
Sub filter: fixed allocation alignment.

10 years agoCore: allow strings without null-termination in ngx_parse_url().
Piotr Sikora [Sat, 27 Feb 2016 01:30:27 +0000 (17:30 -0800)]
Core: allow strings without null-termination in ngx_parse_url().

This fixes buffer over-read while using variables in the "proxy_pass",
"fastcgi_pass", "scgi_pass", and "uwsgi_pass" directives, where result
of string evaluation isn't null-terminated.

Found with MemorySanitizer.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
10 years agoFixed socket inheritance on reload and binary upgrade.
Roman Arutyunyan [Fri, 25 Mar 2016 11:10:38 +0000 (14:10 +0300)]
Fixed socket inheritance on reload and binary upgrade.

On nginx reload or binary upgrade, an attempt is made to inherit listen sockets
from the previous configuration.  Previously, no check for socket type was made
and the inherited socket could have the wrong type.  On binary upgrade, socket
type was not detected at all.  Wrong socket type could lead to errors on that
socket due to different logic and unsupported syscalls.  For example, a UDP
socket, inherited as TCP, lead to the following error after arrival of a
datagram: "accept() failed (102: Operation not supported on socket)".

10 years agoStream: additional logging for UDP.
Vladimir Homutov [Fri, 18 Mar 2016 16:53:22 +0000 (19:53 +0300)]
Stream: additional logging for UDP.

10 years agoWin32: fixed build after 384154fc634f.
Dmitry Volyntsev [Wed, 23 Mar 2016 15:34:05 +0000 (18:34 +0300)]
Win32: fixed build after 384154fc634f.

10 years agoStream: detect port absence in proxy_pass with IP literal.
Roman Arutyunyan [Wed, 23 Mar 2016 14:45:15 +0000 (17:45 +0300)]
Stream: detect port absence in proxy_pass with IP literal.

This is a clone of http commit 26c127bab5ef.

10 years agoResolver: added support for SRV records.
Dmitry Volyntsev [Wed, 23 Mar 2016 14:44:36 +0000 (17:44 +0300)]
Resolver: added support for SRV records.

10 years agoResolver: do not enable resolve timer if provided timeout is zero.
Dmitry Volyntsev [Wed, 23 Mar 2016 14:44:36 +0000 (17:44 +0300)]
Resolver: do not enable resolve timer if provided timeout is zero.

10 years agoResolver: introduced valid field in resolver responses.
Dmitry Volyntsev [Wed, 23 Mar 2016 14:44:36 +0000 (17:44 +0300)]
Resolver: introduced valid field in resolver responses.

It hints the amount of time a response could be considered
as valid.

10 years agoCore: introduced the NGX_DEBUG_PALLOC macro.
Valentin Bartenev [Wed, 23 Mar 2016 14:44:04 +0000 (17:44 +0300)]
Core: introduced the NGX_DEBUG_PALLOC macro.

It allows to turn off accumulation of small pool allocations into a big
preallocated chunk of memory.  This is useful for debugging memory access
with sanitizer, since such accumulation can cover buffer overruns from
being detected.

10 years agoCore: use ngx_palloc_small() to allocate ngx_pool_large_t.
Valentin Bartenev [Wed, 23 Mar 2016 14:44:04 +0000 (17:44 +0300)]
Core: use ngx_palloc_small() to allocate ngx_pool_large_t.

This structure cannot be allocated as a large block anyway, otherwise that will
result in infinite recursion, since each large allocation requires to allocate
another ngx_pool_large_t.

The room for the structure is guaranteed by the NGX_MIN_POOL_SIZE constant.

10 years agoCore: introduced the ngx_palloc_small() function.
Valentin Bartenev [Wed, 23 Mar 2016 14:44:04 +0000 (17:44 +0300)]
Core: introduced the ngx_palloc_small() function.

It deduplicates some code for allocations from memory pool.
No functional changes.

10 years agoCore: moved logging before freeing large blocks of pool.
Valentin Bartenev [Wed, 23 Mar 2016 14:44:04 +0000 (17:44 +0300)]
Core: moved logging before freeing large blocks of pool.

This fixes use-after-free memory access with enabled debug log
when pool->log is allocated as a large block.

10 years agoBacked out server_tokens changes.
Maxim Dounin [Tue, 22 Mar 2016 13:58:38 +0000 (16:58 +0300)]
Backed out server_tokens changes.

Backed out changesets: cf3e75cfa9516b72414dfb4f602dc42035fee5076b96fd01.

10 years agoCache: fixed slots accounting error introduced in c9d680b00744.
Dmitry Volyntsev [Wed, 23 Mar 2016 11:16:31 +0000 (14:16 +0300)]
Cache: fixed slots accounting error introduced in c9d680b00744.

10 years agoReconsidered server_tokens with an empty value.
Ruslan Ermilov [Tue, 22 Mar 2016 12:52:28 +0000 (15:52 +0300)]
Reconsidered server_tokens with an empty value.

An empty value will be treated as "off".

10 years agoHTTP/2: improved debugging of sending control frames.
Valentin Bartenev [Mon, 21 Mar 2016 14:04:21 +0000 (17:04 +0300)]
HTTP/2: improved debugging of sending control frames.

10 years agoEvents: fixed test building with devpoll and eventport on Linux.
Sergey Kandaurov [Mon, 21 Mar 2016 09:36:36 +0000 (12:36 +0300)]
Events: fixed test building with devpoll and eventport on Linux.

Avoid POLLREMOVE and itimerspec redefinition.

10 years agoFix build with -Wmissing-prototypes.
Piotr Sikora [Fri, 18 Mar 2016 23:38:08 +0000 (16:38 -0700)]
Fix build with -Wmissing-prototypes.

Broken in 5eb4d7541107 (1.9.6), fix somehow missed in 3600bbfb43e3.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
10 years agoCache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev [Fri, 18 Mar 2016 12:08:21 +0000 (15:08 +0300)]
Cache: added watermark to reduce IO load when keys_zone is full.

When a keys_zone is full then each next request to the cache is
penalized.  That is, the cache has to evict older files to get a
slot from the keys_zone synchronously.  The patch introduces new
behavior in this scenario.  Manager will try to maintain available
free slots in the keys_zone by cleaning old files in the background.

10 years agoCache: report error if slab allocator fails during cache loading.
Dmitry Volyntsev [Fri, 18 Mar 2016 11:27:30 +0000 (14:27 +0300)]
Cache: report error if slab allocator fails during cache loading.

10 years agoThreads: writing via threads pools in event pipe.
Maxim Dounin [Fri, 18 Mar 2016 03:44:49 +0000 (06:44 +0300)]
Threads: writing via threads pools in event pipe.

The "aio_write" directive is introduced, which enables use of aio
for writing.  Currently it is meaningful only with "aio threads".

Note that aio operations can be done by both event pipe and output
chain, so proper mapping between r->aio and p->aio is provided when
calling ngx_event_pipe() and in output filter.

In collaboration with Valentin Bartenev.

10 years agoThreads: offloading of temp files writing to thread pools.
Maxim Dounin [Fri, 18 Mar 2016 03:44:03 +0000 (06:44 +0300)]
Threads: offloading of temp files writing to thread pools.

The ngx_thread_write_chain_to_file() function introduced, which
uses ngx_file_t thread_handler, thread_ctx and thread_task fields.
The task context structure (ngx_thread_file_ctx_t) is the same for
both reading and writing, and can be safely shared as long as
operations are serialized.

The task->handler field is now always set (and not only when task is
allocated), as the same task can be used with different handlers.

The thread_write flag is introduced in the ngx_temp_file_t structure
to explicitly enable use of ngx_thread_write_chain_to_file() in
ngx_write_chain_to_temp_file() when supported by caller.

In collaboration with Valentin Bartenev.

10 years agoThreads: task pointer stored in ngx_file_t.
Maxim Dounin [Fri, 18 Mar 2016 03:43:52 +0000 (06:43 +0300)]
Threads: task pointer stored in ngx_file_t.

This simplifies the interface of the ngx_thread_read() function.

Additionally, most of the thread operations now explicitly set
file->thread_task, file->thread_handler and file->thread_ctx,
to facilitate use of thread operations in other places.

(Potential problems remain with sendfile in threads though - it uses
file->thread_handler as set in ngx_output_chain(), and it should not
be overwritten to an incompatible one.)

In collaboration with Valentin Bartenev.

10 years agoFixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin [Fri, 18 Mar 2016 02:04:45 +0000 (05:04 +0300)]
Fixed timeouts with threaded sendfile() and subrequests.

If a write event happens after sendfile() but before we've got the
sendfile results in the main thread, this write event will be ignored.
And if no more events will happen, the connection will hang.

Removing the events works in the simple cases, but not always, as
in some cases events are added back by an unrelated code.  E.g.,
the upstream module adds write event in the ngx_http_upstream_init()
to track client aborts.

Fix is to use wev->complete instead.  It is now set to 0 before
a sendfile() task is posted, and it is set to 1 once a write event
happens.  If on completion of the sendfile() task wev->complete is 1,
we know that an event happened while we were executing sendfile(), and
the socket is still ready for writing even if sendfile() did not sent
all the data or returned EAGAIN.

10 years agoStyle.
Ruslan Ermilov [Wed, 16 Mar 2016 11:44:41 +0000 (14:44 +0300)]
Style.

10 years agoTruncation detection in sendfilev() on Solaris.
Maxim Dounin [Tue, 15 Mar 2016 15:26:59 +0000 (18:26 +0300)]
Truncation detection in sendfilev() on Solaris.

While sendfilev() is documented to return -1 with EINVAL set
if the file was truncated, at least Solaris 11 silently returns 0,
and this results in CPU hog.  Added a test to complain appropriately
if 0 is returned.

10 years agoTruncation detection in sendfile() on Linux.
Maxim Dounin [Tue, 15 Mar 2016 15:26:17 +0000 (18:26 +0300)]
Truncation detection in sendfile() on Linux.

This addresses connection hangs as observed in ticket #504, and
CPU hogs with "aio threads; sendfile on" as reported in the mailing list,
see http://mailman.nginx.org/pipermail/nginx-ru/2016-March/057638.html.

The alert is identical to one used on FreeBSD.

10 years agoStream: UDP proxy.
Roman Arutyunyan [Wed, 20 Jan 2016 16:52:12 +0000 (19:52 +0300)]
Stream: UDP proxy.