summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2016-12-10HTTP/2: prevented creating temp files for requests without body.Valentin Bartenev1-2/+4
The problem was introduced by 52bd8cc17f34.
2016-11-28HTTP/2: fixed posted streams handling.Valentin Bartenev3-38/+42
A bug was introduced by 82efcedb310b that could lead to timing out of responses or segmentation fault, when accept_mutex was enabled. The output queue in HTTP/2 can contain frames from different streams. When the queue is sent, all related write handlers need to be called. In order to do so, the streams were added to the h2c->posted queue after handling sent frames. Then this queue was processed in ngx_http_v2_write_handler(). If accept_mutex is enabled, the event's "ready" flag is set but its handler is not called immediately. Instead, the event is added to the ngx_posted_events queue. At the same time in this queue can be events from upstream connections. Such events can result in sending output queue before ngx_http_v2_write_handler() is triggered. And at the time ngx_http_v2_write_handler() is called, the output queue can be already empty with some streams added to h2c->posted. But after 82efcedb310b, these streams weren't processed if all frames have already been sent and the output queue was empty. This might lead to a situation when a number of streams were get stuck in h2c->posted queue for a long time. Eventually these streams might get closed by the send timeout. In the worst case this might also lead to a segmentation fault, if already freed stream was left in the h2c->posted queue. This could happen if one of the streams was terminated but wasn't closed, due to the HEADERS frame or a partially sent DATA frame left in the output queue. If this happened the ngx_http_v2_filter_cleanup() handler removed the stream from the h2c->waiting or h2c->posted queue on termination stage, before the frame has been sent, and the stream was again added to the h2c->posted queue after the frame was sent. In order to fix all these problems and simplify the code, write events of fake stream connections are now added to ngx_posted_events instead of using a custom h2c->posted queue.
2016-12-08Map: the "volatile" parameter.Ruslan Ermilov2-2/+28
By default, "map" creates cacheable variables [1]. With this parameter it creates a non-cacheable variable. An original idea was to deduce the cacheability of the "map" variable by checking the cacheability of variables specified in source and resulting values, but it turned to be too hard. For example, a cacheable variable can be overridden with the "set" directive or with the SSI "set" command. Also, keeping "map" variables cacheable by default is good for performance reasons. This required adding a new parameter. [1] Before db699978a33f (1.11.0), the cacheability of the "map" variable could vary depending on the cacheability of variables specified in resulting values (ticket #1090). This is believed to be a bug rather than a feature.
2016-12-08Map: simplified "map" block parser.Ruslan Ermilov2-2/+4
No functional changes.
2016-12-08Slab: commented bitmap initialization for small allocations.Ruslan Ermilov1-0/+1
2016-12-07Slab: free pages statistics.Ruslan Ermilov2-0/+6
2016-12-07Slab: slots statistics.Ruslan Ermilov2-11/+57
For each slot, the number of total and used entries, as well as the number of allocation requests and failures, are tracked.
2016-12-07Slab: simplified some math.Ruslan Ermilov1-17/+12
No functional changes.
2016-12-07Slab: simplified allocation from slots.Ruslan Ermilov1-79/+61
Removed code that would cause an endless loop, and removed condition check that is always false. The first page in the slot list is guaranteed to satisfy an allocation.
2016-12-07Slab: fixed the number of pages calculation.Ruslan Ermilov1-0/+1
When estimating the number of pages, do not count memory for slots. In some cases this gives one extra usable memory page.
2016-12-07Slab: added comment about list heads.Ruslan Ermilov1-1/+4
2016-12-07Slab: improved code readability.Ruslan Ermilov1-54/+49
No functional changes.
2016-12-07Core: fixed environment on exit.Maxim Dounin1-8/+40
On exit environment allocated from a pool is no longer available, leading to a segmentation fault if, for example, a library tries to use it from an atexit() handler. Fix is to allocate environment via ngx_alloc() instead, and explicitly free it using a pool cleanup handler if it's no longer used (e.g., on configuration reload).
2016-12-07Perl: removed special environment handling for the perl module.Maxim Dounin1-12/+1
In Perl 5.8.6 the default was switched to use putenv() when used as embedded library unless "PL_use_safe_putenv = 0" is explicitly used in the code. Therefore, for modern versions of Perl it is no longer necessary to restore previous environment when calling perl_destruct().
2016-12-07Perl: added PERL_SET_INTERP().Maxim Dounin1-0/+8
For Perl compiled with threads, without PERL_SET_INTERP() the PL_curinterp remains set to the first interpreter created (that is, one created at original start). As a result after a reload Perl thinks that operations are done withing a thread, and, most notably, denies to change environment. For example, the following code properly works on original start, but fails after a reload: perl 'sub { my $r = shift; $r->send_http_header("text/plain"); $ENV{TZ} = "UTC"; $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n"); $ENV{TZ} = "Europe/Moscow"; $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n"); return OK; }'; To fix this, PERL_SET_INTERP() added anywhere where PERL_SET_CONTEXT() was previously used. Note that PERL_SET_INTERP() doesn't seem to be documented anywhere. Yet it is used in some other software, and also seems to be the only solution possible.
2016-12-07Fixed spelling of logical AND operator, no functional changes.Sergey Kandaurov1-1/+1
Found by PVS-Studio.
2016-11-22Mp4: fixed setting wrong mdat atom size in very rare cases.hucongcong1-1/+3
Atom size is the sum of atom header size and atom data size. The specification says that the first 4 bytes are set to one when the atom size is greater than the maximum unsigned 32-bit value. Which means atom header size should be considered when the comparison takes place between atom data size and 0xffffffff.
2016-12-05SSL: $ssl_curves (ticket #1088).Maxim Dounin4-0/+76
The variable contains a list of curves as supported by the client. Known curves are listed by their names, unknown ones are shown in hex, e.g., "0x001d:prime256v1:secp521r1:secp384r1". Note that OpenSSL uses session data for SSL_get1_curves(), and it doesn't store full list of curves supported by the client when serializing a session. As a result $ssl_curves is only available for new sessions (and will be empty for reused ones). The variable is only meaningful when using OpenSSL 1.0.2 and above. With older versions the variable is empty.
2016-12-05SSL: $ssl_ciphers (ticket #870).Maxim Dounin4-0/+92
The variable contains list of ciphers as supported by the client. Known ciphers are listed by their names, unknown ones are shown in hex, e.g., ""AES128-SHA:AES256-SHA:0x00ff". The variable is fully supported only when using OpenSSL 1.0.2 and above. With older version there is an attempt to provide some information using SSL_get_shared_ciphers(). It only lists known ciphers though. Moreover, as OpenSSL uses session data for SSL_get_shared_ciphers(), and it doesn't store relevant data when serializing a session. As a result $ssl_ciphers is only available for new sessions (and not available for reused ones) when using OpenSSL older than 1.0.2.
2016-12-05SSL: $ssl_client_v_start, $ssl_client_v_end, $ssl_client_v_remain.Maxim Dounin3-0/+193
2016-12-05SSL: $ssl_client_verify extended with a failure reason.Maxim Dounin1-8/+18
Now in case of a verification failure $ssl_client_verify contains "FAILED:<reason>", similar to Apache's SSL_CLIENT_VERIFY, e.g., "FAILED:certificate has expired". Detailed description of possible errors can be found in the verify(1) manual page as provided by OpenSSL.
2016-12-05OCSP stapling: improved error logging context.Maxim Dounin1-1/+19
It now logs the IP address of the responder used (if it's already known), as well as the certificate name.
2016-12-05OCSP stapling: added certificate name to warnings.Maxim Dounin3-5/+36
2016-12-05OCSP stapling: added http response status logging.Maxim Dounin1-6/+9
2016-12-05OCSP stapling: style.Maxim Dounin1-10/+12
2016-12-03Slab: improved double free detection.Ruslan Ermilov1-1/+1
Previously, an attempt to double free the starting page of the free range was not detected.
2016-12-03Slab: always show the requested allocation size in debug messages.Ruslan Ermilov1-1/+0
Previously, allocations smaller than min_size were shown as min_size.
2016-12-03Slab: style.Ruslan Ermilov1-3/+3
Removed redundant parentheses. No functional changes.
2016-11-21Events: improved error event handling for UDP sockets.Dmitry Volyntsev4-30/+19
Normally, the epoll module calls the read and write handlers depending on whether EPOLLIN and EPOLLOUT are reported by epoll_wait(). No error processing is done in the module, the handlers are expected to get an error when doing I/O. If an error event is reported without EPOLLIN and EPOLLOUT, the module set both EPOLLIN and EPOLLOUT to ensure the error event is handled at least in one active handler. This works well unless the error is delivered along with only one of EPOLLIN or EPOLLOUT, and the corresponding handler does not do any I/O. For example, it happened when getting EPOLLERR|EPOLLOUT from epoll_wait() upon receiving "ICMP port unreachable" while proxying UDP. As the write handler had nothing to send it was not able to detect and log an error, and did not switch to the next upstream. The fix is to unconditionally set EPOLLIN and EPOLLOUT in case of an error event. In the aforementioned case, this causes the read handler to be called which does recv() and detects an error. In addition to the epoll module, analogous changes were made in devpoll/eventport/poll.
2016-11-28HTTP/2: fixed saving preread buffer to temp file (ticket #1143).Valentin Bartenev1-0/+3
Previously, a request body bigger than "client_body_buffer_size" wasn't written into a temporary file if it has been pre-read entirely. The preread buffer is freed after processing, thus subsequent use of it might result in sending corrupted body or cause a segfault.
2016-11-21Version bump.Maxim Dounin1-2/+2
2016-11-14Upstream: handling of upstream SSL handshake timeouts.Maxim Dounin1-0/+7
Previously SSL handshake timeouts were not properly logged, and resulted in 502 errors instead of 504 (ticket #1126).
2016-11-10Range filter: only initialize ctx->ranges in main request.hucongcong1-6/+6
It is not necessary to initialize ctx->ranges in all request, because ctx->ranges in subrequest will be reassigned to ctx->ranges of main request.
2016-11-10Core: slight optimization in ngx_chain_update_chains().hucongcong1-7/+9
It is not necessary to traverse *busy and link the *out when *out is NULL.
2016-11-04Style: switch.Ruslan Ermilov2-3/+0
2016-11-03Cache: prefix-based temporary files.Maxim Dounin4-40/+46
On Linux, the rename syscall can be slow due to a global file system lock, acquired for the entire rename operation, unless both old and new files are in the same directory. To address this temporary files are now created in the same directory as the expected resulting cache file when using the "use_temp_path=off" parameter. This change mostly reverts 99639bfdfa2a and 3281de8142f5, restoring the behaviour as of a9138c35120d (with minor changes).
2016-11-03Upstream: avoid holding a cache node with upgraded connections.Maxim Dounin1-0/+17
Holding a cache node lock doesn't make sense as we can't use caching anyway, and results in "ignore long locked inactive cache entry" alerts if a node is locked for a long time. The same is done for unbuffered connections, as they can be alive for a long time as well.
2016-11-02Cache: proxy_cache_max_range_offset and friends.Dmitry Volyntsev6-0/+105
It configures a threshold in bytes, above which client range requests are not cached. In such a case the client's Range header is passed directly to a proxied server.
2016-11-02HTTP/2: flow control debugging.Sergey Kandaurov1-0/+4
2016-11-01Perl: fixed optimization in SSI command handler.Maxim Dounin1-1/+1
As the pointer to the first argument was tested instead of the argument itself, array of arguments was always created, even if there were no arguments. Fix is to test args[0] instead of args. Found by Coverity (CID 1356862).
2016-10-31HTTP/2: slightly improved debugging.Ruslan Ermilov1-3/+4
2016-10-17Upstream: removed ngx_http_upstream_srv_conf_t.default_port.Ruslan Ermilov2-3/+0
This is an API change.
2016-10-17Upstream: don't consider default_port when matching upstreams.Ruslan Ermilov1-6/+0
The only thing that default_port comparison did in the current code is prevented implicit upstreams to the same address/port from being aliased for http and https, e.g.: proxy_pass http://10.0.0.1:12345; proxy_pass https://10.0.0.1:12345; This is inconsistent because it doesn't work for a similar case with uswgi_pass: uwsgi_pass uwsgi://10.0.0.1:12345; uwsgi_pass suwsgi://10.0.0.1:12345; or with an explicit upstream: upstream u { server 10.0.0.1:12345; } proxy_pass http://u; proxy_pass https://u; Before c9059bd5445b, default_port comparison was needed to differentiate implicit upstreams in proxy_pass http://example.com; and proxy_pass https://example.com; as u->port was not set.
2016-10-17Upstream: consistently initialize explicit upstreams.Ruslan Ermilov1-0/+2
When an upstream{} block follows a proxy_pass reference to it, such an upstream inherited port and default_port settings from proxy_pass. This was different from when they came in another order (see ticket #1059). Explicit upstreams should not have port and default_port in any case. This fixes the following case: server { location / { proxy_pass http://u; } ... } upstream u { server 127.0.0.1; } server { location / { proxy_pass https://u; } ... } but not the following: server { location / { proxy_pass http://u; } ... } server { location / { proxy_pass https://u; } ... } upstream u { server 127.0.0.1; }
2016-10-31Upstream: do not unnecessarily create per-request upstreams.Ruslan Ermilov2-34/+34
If proxy_pass (and friends) with variables evaluates an upstream specified with literal address, nginx always created a per-request upstream. Now, if there's a matching upstream specified in the configuration (either implicit or explicit), it will be used instead.
2016-10-31Upstream: added the ngx_http_upstream_resolved_t.name field.Ruslan Ermilov9-22/+14
This fixes inconsistency in what is stored in the "host" field. Normally it would contain the "host" part of the parsed URL (e.g., proxy_pass with variables), but for the case of an implicit upstream specified with literal address it contained the text representation of the socket address (that is, host including port for IP). Now the "host" field always contains the "host" part of the URL, while the text representation of the socket address is stored in the newly added "name" field. The ngx_http_upstream_create_round_robin_peer() function was modified accordingly in a way to be compatible with the code that does not know about the new "name" field. The "stream" code was similarly modified except for not adding compatibility in ngx_stream_upstream_create_round_robin_peer(). This change is also a prerequisite for the next change.
2016-10-31Upstream: removed unnecessary condition in proxy_eval() and friends.Ruslan Ermilov5-5/+5
The first condition added in d3454e719bbb should have just replaced the second one.
2016-10-31HTTP/2: limited maximum number of requests in connection.Valentin Bartenev3-8/+32
The new directive "http2_max_requests" is introduced. From users point of view it works quite similar to "keepalive_requests" but has significantly bigger default value that is more suitable for HTTP/2.
2016-10-27Mp4: introduced custom version of ngx_atofp().Maxim Dounin1-14/+60
This allows to correctly parse "start" and "end" arguments without null-termination (ticket #475), and also fixes rounding errors observed with strtod() when using i387 instructions.
2016-10-16Proxy: support variables for proxy_method directive.Dmitry Lazurkin1-6/+10