]> git.kaiwu.me - nginx.git/log
nginx.git
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.

10 years agoStream: post first read events from client and upstream.
Roman Arutyunyan [Tue, 15 Mar 2016 12:55:23 +0000 (15:55 +0300)]
Stream: post first read events from client and upstream.

The main proxy function ngx_stream_proxy_process() can terminate the stream
session.  The code, following it, should check its return code to make sure the
session still exists.  This happens in client and upstream initialization
functions.  Swapping ngx_stream_proxy_process() call with the code, that
follows it, leaves the same problem vice versa.

In future ngx_stream_proxy_process() will call ngx_stream_proxy_next_upstream()
making it too complicated to know if stream session still exists after this
call.

Now ngx_stream_proxy_process() is called from posted event handlers in both
places with no code following it.  The posted event is automatically removed
once session is terminated.

10 years agoWin32: fixed build after cf3e75cfa951.
Ruslan Ermilov [Tue, 15 Mar 2016 12:15:30 +0000 (15:15 +0300)]
Win32: fixed build after cf3e75cfa951.

10 years agoWin32: fixed build after cf3e75cfa951.
Ruslan Ermilov [Tue, 15 Mar 2016 12:10:41 +0000 (15:10 +0300)]
Win32: fixed build after cf3e75cfa951.

10 years agoAdded variables support to server_tokens.
Ruslan Ermilov [Tue, 15 Mar 2016 10:36:19 +0000 (13:36 +0300)]
Added variables support to server_tokens.

It can now be set to "off" conditionally, e.g. using the map
directive.

An empty value will disable the emission of the Server: header
and the signature in error messages generated by nginx.

Any other value is treated as "on", meaning that full nginx
version is emitted in the Server: header and error messages
generated by nginx.

10 years agoFixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev [Mon, 14 Mar 2016 19:42:35 +0000 (22:42 +0300)]
Fixed handling of EAGAIN with sendfile in threads.

10 years agoEvents: fixed error logging in devpoll.
Roman Arutyunyan [Mon, 14 Mar 2016 21:04:04 +0000 (00:04 +0300)]
Events: fixed error logging in devpoll.

10 years agoFixed compilation with -Wmissing-prototypes.
Sergey Kandaurov [Mon, 14 Mar 2016 16:23:23 +0000 (19:23 +0300)]
Fixed compilation with -Wmissing-prototypes.

10 years agoUpstream: avoid closing client connection in edge case.
Justin Li [Wed, 9 Mar 2016 03:31:55 +0000 (22:31 -0500)]
Upstream: avoid closing client connection in edge case.

If proxy_cache is enabled, and proxy_no_cache tests true, it was previously
possible for the client connection to be closed after a 304. The fix is to
recheck r->header_only after the final cacheability is determined, and end the
request if no longer cacheable.

Example configuration:

proxy_cache foo;
proxy_cache_bypass 1;
proxy_no_cache 1;

If a client sends If-None-Match, and the upstream server returns 200 with a
matching ETag, no body should be returned to the client. At the start of
ngx_http_upstream_send_response proxy_no_cache is not yet tested, thus cacheable
is still 1 and downstream_error is set.

However, by the time the downstream_error check is done in process_request,
proxy_no_cache has been tested and cacheable is set to 0. The client connection
is then closed, regardless of keepalive.

10 years agoUpstream: fixed "zero size buf" alerts with cache (ticket #918).
Maxim Dounin [Thu, 10 Mar 2016 18:58:03 +0000 (21:58 +0300)]
Upstream: fixed "zero size buf" alerts with cache (ticket #918).

If caching was used, "zero size buf in output" alerts might appear
in logs if a client prematurely closed connection.  Alerts appeared
in the following situation:

- writing to client returned an error, so event pipe
  drained all busy buffers leaving body output filters
  in an invalid state;

- when upstream response was fully received,
  ngx_http_upstream_finalize_request() tried to flush
  all pending data.

Fix is to avoid flushing body if p->downstream_error is set.

10 years agoConfigure: style.
Ruslan Ermilov [Thu, 10 Mar 2016 15:31:05 +0000 (18:31 +0300)]
Configure: style.

Generate Makefile with not so long lines.

10 years agoDynamic modules: do not overwrite old modules on install.
Maxim Dounin [Thu, 10 Mar 2016 13:50:13 +0000 (16:50 +0300)]
Dynamic modules: do not overwrite old modules on install.

Just using "cp" is incorrect, as it will overwrite old files
possibly used by OS, leading to unexpected effects.  Changed
to "mv + cp", much like used for the main binary.

10 years agoConfigure: style.
Ruslan Ermilov [Thu, 10 Mar 2016 07:43:00 +0000 (10:43 +0300)]
Configure: style.

Removed extraneous braces around shell variables.

10 years agoCopy filter: fixed sendfile aio handlers to set ctx->aio.
Maxim Dounin [Thu, 3 Mar 2016 18:14:19 +0000 (21:14 +0300)]
Copy filter: fixed sendfile aio handlers to set ctx->aio.

Sendfile handlers (aio preload and thread handler) are called within
ctx->output_filter() in ngx_output_chain(), and hence ctx->aio cannot
be set directly in ngx_output_chain().  Meanwhile, it must be set to
make sure loop within ngx_output_chain() will be properly terminated.

There are no known cases that trigger the problem, though in theory
something like aio + sub filter (something that needs body in memory,
and can also free some memory buffers) + sendfile can result in
"task already active" and "second aio post" alerts.

The fix is to set ctx->aio in ngx_http_copy_aio_sendfile_preload()
and ngx_http_copy_thread_handler().

For consistency, ctx->aio is no longer set explicitly in
ngx_output_chain_copy_buf(), as it's now done in
ngx_http_copy_thread_handler().

10 years agoFixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin [Thu, 3 Mar 2016 18:14:12 +0000 (21:14 +0300)]
Fixed sendfile in threads (or with aio preload) and subrequests.

If sendfile in threads is used, it is possible that multiple
subrequests will trigger multiple ngx_linux_sendfile_thread() calls,
as operations are only serialized in output chain based on r->aio,
that is, on subrequest level.

This resulted in "task #N already active" alerts, in particular, when
running proxy_store.t with "aio threads; sendfile on;".

Fix is to tolerate duplicate calls, with an additional safety check
that the file is the same as previously used.

The same problem also affects "aio on; sendfile on;" on FreeBSD
(previously known as "aio sendfile;"), where aio->preload_handler()
could be called multiple times due to similar reasons, resulting in
"second aio post" alerts.  Fix is the same as well.

It is also believed that similar problems can arise if a filter
calls the next body filter multiple times for some reason.  These are
mostly theoretical though.

10 years agoIntroduced the ngx_chain_to_iovec() function.
Valentin Bartenev [Thu, 3 Mar 2016 15:41:05 +0000 (18:41 +0300)]
Introduced the ngx_chain_to_iovec() function.

It's similar to ngx_output_chain_to_iovec() and uses only preallocated memory.

10 years agoRequest body: moved handling of the last part in the save filter.
Valentin Bartenev [Tue, 1 Mar 2016 12:18:07 +0000 (15:18 +0300)]
Request body: moved handling of the last part in the save filter.

No functional changes.

10 years agoDynamic modules: perl.
Ruslan Ermilov [Fri, 26 Feb 2016 11:27:04 +0000 (14:27 +0300)]
Dynamic modules: perl.

10 years agoDynamic modules: expose the "modules" target.
Ruslan Ermilov [Mon, 29 Feb 2016 15:52:33 +0000 (18:52 +0300)]
Dynamic modules: expose the "modules" target.

10 years agoDynamic modules: removed unnecessary initialization.
Ruslan Ermilov [Thu, 25 Feb 2016 13:29:51 +0000 (16:29 +0300)]
Dynamic modules: removed unnecessary initialization.

It became unnecessary after 85dea406e18f.

10 years agoDynamic modules: make sure to call config.make for dynamic addons.
Ruslan Ermilov [Thu, 25 Feb 2016 12:22:05 +0000 (15:22 +0300)]
Dynamic modules: make sure to call config.make for dynamic addons.

10 years agoVersion bump.
Ruslan Ermilov [Thu, 25 Feb 2016 13:28:42 +0000 (16:28 +0300)]
Version bump.

10 years agorelease-1.9.12 tag
Maxim Dounin [Wed, 24 Feb 2016 14:53:23 +0000 (17:53 +0300)]
release-1.9.12 tag

10 years agonginx-1.9.12-RELEASE release-1.9.12
Maxim Dounin [Wed, 24 Feb 2016 14:53:22 +0000 (17:53 +0300)]
nginx-1.9.12-RELEASE

10 years agoHTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev [Wed, 24 Feb 2016 12:58:07 +0000 (15:58 +0300)]
HTTP/2: implemented per request timeouts (closes #626).

Previously, there were only three timeouts used globally for the whole HTTP/2
connection:

 1. Idle timeout for inactivity when there are no streams in processing
    (the "http2_idle_timeout" directive);

 2. Receive timeout for incomplete frames when there are no streams in
    processing (the "http2_recv_timeout" directive);

 3. Send timeout when there are frames waiting in the output queue
    (the "send_timeout" directive on a server level).

Reaching one of these timeouts leads to HTTP/2 connection close.

This left a number of scenarios when a connection can get stuck without any
processing and timeouts:

 1. A client has sent the headers block partially so nginx starts processing
    a new stream but cannot continue without the rest of HEADERS and/or
    CONTINUATION frames;

 2. When nginx waits for the request body;

 3. All streams are stuck on exhausted connection or stream windows.

The first idea that was rejected was to detect when the whole connection
gets stuck because of these situations and set the global receive timeout.
The disadvantage of such approach would be inconsistent behaviour in some
typical use cases.  For example, if a user never replies to the browser's
question about where to save the downloaded file, the stream will be
eventually closed by a timeout.  On the other hand, this will not happen
if there's some activity in other concurrent streams.

Now almost all the request timeouts work like in HTTP/1.x connections, so
the "client_header_timeout", "client_body_timeout", and "send_timeout" are
respected.  These timeouts close the request.

The global timeouts work as before.

Previously, the c->write->delayed flag was abused to avoid setting timeouts on
stream events.  Now, the "active" and "ready" flags are manipulated instead to
control the processing of individual streams.

10 years agoHTTP/2: always use temporary pool for processing headers.
Valentin Bartenev [Wed, 24 Feb 2016 13:05:47 +0000 (16:05 +0300)]
HTTP/2: always use temporary pool for processing headers.

This is required for implementing per request timeouts.

Previously, the temporary pool was used only during skipping of
headers and the request pool was used otherwise.  That required
switching of pools if the request was closed while parsing.

It wasn't a problem since the request could be closed only after
the validation of the fully parsed header.  With the per request
timeouts, the request can be closed at any moment, and switching
of pools in the middle of parsing header name or value becomes a
problem.

To overcome this, the temporary pool is now always created and
used.  Special checks are added to keep it when either the stream
is being processed or until header block is fully parsed.

10 years agoHTTP/2: cleaned up state while closing stream.
Valentin Bartenev [Wed, 24 Feb 2016 13:05:46 +0000 (16:05 +0300)]
HTTP/2: cleaned up state while closing stream.

Without this the state might keep pointing to already closed stream.

10 years agoFixed buffer over-read while logging invalid request headers.
Valentin Bartenev [Wed, 24 Feb 2016 13:01:23 +0000 (16:01 +0300)]
Fixed buffer over-read while logging invalid request headers.

Since 667aaf61a778 (1.1.17) the ngx_http_parse_header_line() function can return
NGX_HTTP_PARSE_INVALID_HEADER when a header contains NUL character.  In this
case the r->header_end pointer isn't properly initialized, but the log message
in ngx_http_process_request_headers() hasn't been adjusted.  It used the pointer
in size calculation, which might result in up to 2k buffer over-read.

Found with afl-fuzz.

10 years agoConfigure: added "build" target.
Maxim Dounin [Fri, 19 Feb 2016 15:13:54 +0000 (18:13 +0300)]
Configure: added "build" target.

The "build" target introduced to do all build-related tasks, and
it is now used in Makefile and in objs/Makefile as a dependency for
the "install" target.

In particular, this resolves problems as observed with dynamic modules
by people trying to do "make install" without calling "make" first.

10 years agoSSL: avoid calling SSL_shutdown() during handshake (ticket #901).
Maxim Dounin [Fri, 19 Feb 2016 14:27:30 +0000 (17:27 +0300)]
SSL: avoid calling SSL_shutdown() during handshake (ticket #901).

This fixes "called a function you should not call" and
"shutdown while in init" errors as observed with OpenSSL 1.0.2f
due to changes in how OpenSSL handles SSL_shutdown() during
SSL handshakes.

10 years agoSSL: fixed SSL_shutdown() comment.
Maxim Dounin [Fri, 19 Feb 2016 14:27:23 +0000 (17:27 +0300)]
SSL: fixed SSL_shutdown() comment.

10 years agoHeaders filter: fixed "add_header ... '' always".
Ruslan Ermilov [Thu, 18 Feb 2016 12:49:11 +0000 (15:49 +0300)]
Headers filter: fixed "add_header ... '' always".

The "always" parameter was ignored if the header value was empty.

10 years agoConfigure: skip building OpenSSL documentation to conserve time.
Sergey Kandaurov [Fri, 19 Feb 2016 10:31:55 +0000 (13:31 +0300)]
Configure: skip building OpenSSL documentation to conserve time.

The install_sw target first appeared in OpenSSL 0.9.7e and is documented since
OpenSSL 1.0.0 as the way to install the OpenSSL software without documentation.

10 years agoConfigure: fixed static nginx build with OpenSSL (ticket #903).
Ruslan Ermilov [Thu, 18 Feb 2016 08:39:57 +0000 (11:39 +0300)]
Configure: fixed static nginx build with OpenSSL (ticket #903).

Before 7142b04337d6, it was possible to build the OpenSSL library
along with nginx, and link nginx statically with this library
(--with-openssl=DIR --with-ld-opt=-static --with-http_ssl_module).
This was broken on Linux by not adding -ldl after -lcrypto.

The fix also makes it possible to link nginx statically on Linux
with the system OpenSSL library, which never worked before.

10 years agoCore: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov [Thu, 18 Feb 2016 10:58:49 +0000 (13:58 +0300)]
Core: added support for more than 64 CPUs in worker_cpu_affinity.

10 years agoHTTP/2: added debug logging of response headers.
Valentin Bartenev [Tue, 16 Feb 2016 14:49:14 +0000 (17:49 +0300)]
HTTP/2: added debug logging of response headers.

Because of HPACK compression it's hard to see what headers are actually
sent by the server.

10 years agoHTTP/2: use local pointer instead of r->connection.
Valentin Bartenev [Tue, 16 Feb 2016 14:49:14 +0000 (17:49 +0300)]
HTTP/2: use local pointer instead of r->connection.

No functional changes.

10 years agoCore: improved logging on invalid NGINX variable (ticket #900).
Maxim Dounin [Mon, 15 Feb 2016 14:41:52 +0000 (17:41 +0300)]
Core: improved logging on invalid NGINX variable (ticket #900).

10 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Sat, 13 Feb 2016 04:28:14 +0000 (07:28 +0300)]
Updated OpenSSL used for win32 builds.

10 years agoWin32: simplified and improved handling of MSVC versions.
Maxim Dounin [Sat, 13 Feb 2016 03:47:34 +0000 (06:47 +0300)]
Win32: simplified and improved handling of MSVC versions.

Now we always set NGX_CC_NAME to "msvc", and additionally test compiler
version as reported by "cl" in auto/cc/msvc (the same version is also
available via the _MSC_VER define).  In particular, this approach allows
to properly check for C99 variadic macros support, which previously was
not used with MSVC versions not explicitly recognized.

Now unneeded wildcards in NGX_CC_NAME tests for msvc removed accordingly,
as well as unused wildcards for owc and icc.

10 years agoHTTP/2: fixed undefined behavior in ngx_http_v2_huff_encode().
Valentin Bartenev [Fri, 12 Feb 2016 13:36:20 +0000 (16:36 +0300)]
HTTP/2: fixed undefined behavior in ngx_http_v2_huff_encode().

When the "pending" value is zero, the "buf" will be right shifted
by the width of its type, which results in undefined behavior.

Found by Coverity (CID 1352150).

10 years agoHTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev [Thu, 11 Feb 2016 12:35:36 +0000 (15:35 +0300)]
HTTP/2: implemented HPACK Huffman encoding for response headers.

This reduces the size of headers by over 30% on average.

Based on the patch by Vlad Krasnov:
http://mailman.nginx.org/pipermail/nginx-devel/2015-December/007682.html

10 years agoDynamic modules: fixed a version mismatch message (ticket #898).
Ruslan Ermilov [Thu, 11 Feb 2016 15:46:46 +0000 (18:46 +0300)]
Dynamic modules: fixed a version mismatch message (ticket #898).

Based on a patch by Takashi Takizawa.

10 years agoStream: initialize variable right before using it.
Roman Arutyunyan [Thu, 11 Feb 2016 11:20:26 +0000 (14:20 +0300)]
Stream: initialize variable right before using it.