summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2016-03-15Stream: post first read events from client and upstream.Roman Arutyunyan1-12/+10
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.
2016-03-15Win32: fixed build after cf3e75cfa951.Ruslan Ermilov1-0/+4
2016-03-15Win32: fixed build after cf3e75cfa951.Ruslan Ermilov1-0/+4
2016-03-15Added variables support to server_tokens.Ruslan Ermilov5-47/+166
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.
2016-03-14Fixed handling of EAGAIN with sendfile in threads.Valentin Bartenev1-1/+6
2016-03-15Events: fixed error logging in devpoll.Roman Arutyunyan1-1/+1
2016-03-14Fixed compilation with -Wmissing-prototypes.Sergey Kandaurov2-2/+2
2016-03-08Upstream: avoid closing client connection in edge case.Justin Li1-0/+5
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.
2016-03-10Upstream: fixed "zero size buf" alerts with cache (ticket #918).Maxim Dounin1-1/+2
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.
2016-03-03Copy filter: fixed sendfile aio handlers to set ctx->aio.Maxim Dounin2-5/+12
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().
2016-03-03Fixed sendfile in threads (or with aio preload) and subrequests.Maxim Dounin2-0/+24
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.
2016-03-03Introduced the ngx_chain_to_iovec() function.Valentin Bartenev1-50/+60
It's similar to ngx_output_chain_to_iovec() and uses only preallocated memory.
2016-03-01Request body: moved handling of the last part in the save filter.Valentin Bartenev1-69/+40
No functional changes.
2016-02-25Dynamic modules: removed unnecessary initialization.Ruslan Ermilov1-1/+0
It became unnecessary after 85dea406e18f.
2016-02-25Version bump.Ruslan Ermilov1-2/+2
2016-02-24HTTP/2: implemented per request timeouts (closes #626).Valentin Bartenev3-63/+147
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.
2016-02-24HTTP/2: always use temporary pool for processing headers.Valentin Bartenev2-25/+37
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.
2016-02-24HTTP/2: cleaned up state while closing stream.Valentin Bartenev1-0/+4
Without this the state might keep pointing to already closed stream.
2016-02-24Fixed buffer over-read while logging invalid request headers.Valentin Bartenev1-4/+3
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.
2016-02-19SSL: avoid calling SSL_shutdown() during handshake (ticket #901).Maxim Dounin1-0/+13
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.
2016-02-19SSL: fixed SSL_shutdown() comment.Maxim Dounin1-1/+1
2016-02-18Headers filter: fixed "add_header ... '' always".Ruslan Ermilov1-8/+8
The "always" parameter was ignored if the header value was empty.
2016-02-18Core: added support for more than 64 CPUs in worker_cpu_affinity.Vladimir Homutov6-59/+83
2016-02-16HTTP/2: added debug logging of response headers.Valentin Bartenev1-0/+41
Because of HPACK compression it's hard to see what headers are actually sent by the server.
2016-02-16HTTP/2: use local pointer instead of r->connection.Valentin Bartenev1-2/+2
No functional changes.
2016-02-15Core: improved logging on invalid NGINX variable (ticket #900).Maxim Dounin1-0/+6
2016-02-12HTTP/2: fixed undefined behavior in ngx_http_v2_huff_encode().Valentin Bartenev1-2/+6
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).
2016-02-11HTTP/2: implemented HPACK Huffman encoding for response headers.Valentin Bartenev3-56/+343
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
2016-02-11Dynamic modules: fixed a version mismatch message (ticket #898).Ruslan Ermilov1-1/+1
Based on a patch by Takashi Takizawa.
2016-02-11Stream: initialize variable right before using it.Roman Arutyunyan1-2/+2
2016-02-11Stream: removed useless typedef.Roman Arutyunyan1-3/+0
2016-02-09Core: ngx_module_t compatibility with C++.Piotr Sikora1-1/+1
Changes to NGX_MODULE_V1 and ngx_module_t in 85dea406e18f (1.9.11) broke all modules written in C++, because ISO C++11 does not allow conversion from string literal to char *. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2016-02-10Version bump.Maxim Dounin1-2/+2
2016-02-04Dynamic modules.Maxim Dounin5-10/+653
The auto/module script is extended to understand ngx_module_link=DYNAMIC. When set, it links the module as a shared object rather than statically into nginx binary. The module can later be loaded using the "load_module" directive. New auto/module parameter ngx_module_order allows to define module loading order in complex cases. By default the order is set based on ngx_module_type. 3rd party modules can be compiled dynamically using the --add-dynamic-module configure option, which will preset ngx_module_link to "DYNAMIC" before calling the module config script. Win32 support is rudimentary, and only works when using MinGW gcc (which is able to handle exports/imports automatically). In collaboration with Ruslan Ermilov.
2016-02-04Dynamic modules: dlopen() support.Maxim Dounin10-0/+127
2016-02-04Dynamic modules: changed ngx_modules to cycle->modules.Maxim Dounin16-140/+148
2016-02-04Dynamic modules: moved module-related stuff to separate files.Maxim Dounin10-95/+149
2016-02-04HTTP/2: fixed possible buffer overrun (ticket #893).Valentin Bartenev1-2/+2
Due to greater priority of the unary plus operator over the ternary operator the expression didn't work as expected. That might result in one byte less allocation than needed for the HEADERS frame buffer.
2016-02-02HTTP/2: fixed padding handling in HEADERS frame with CONTINUATION.Valentin Bartenev1-1/+11
2016-02-02HTTP/2: fixed request length accounting.Valentin Bartenev1-1/+10
Now it includes not only the received body size, but the size of headers block as well.
2016-02-02HTTP/2: fixed excessive memory allocation for pool cleanup.Valentin Bartenev1-1/+1
2016-02-02HTTP/2: removed unused field from ngx_http_v2_stream_t.Valentin Bartenev1-1/+0
2015-12-17Resolver: style.Ruslan Ermilov1-9/+8
Use the original query name in error and debug messages when processing PTR responses.
2015-12-17Resolver: improved PTR response processing.Ruslan Ermilov1-28/+74
The previous code only parsed the first answer, without checking its type, and required a compressed RR name. The new code checks the RR type, supports responses with multiple answers, and doesn't require the RR name to be compressed. This has a side effect in limited support of CNAME. If a response includes both CNAME and PTR RRs, like when recursion is enabled on the server, PTR RR is handled. Full CNAME support in PTR response is not implemented in this change.
2015-12-17Resolver: style.Ruslan Ermilov1-13/+13
Renamed argument in ngx_resolver_process_a() for consistency.
2016-02-02Resolver: free TCP buffers on resolver cleanup.Roman Arutyunyan1-0/+10
2016-02-02Resolver: fixed possible resource leak introduced in 5a16d40c63de.Ruslan Ermilov1-0/+2
Found by Coverity (CID 1351175).
2016-01-28Resolver: TCP support.Roman Arutyunyan2-51/+549
Resend DNS query over TCP once UDP response came truncated.
2016-01-28Resolver: per-request DNS server balancer.Roman Arutyunyan2-5/+17
Previously, a global server balancer was used to assign the next DNS server to send a query to. That could lead to a non-uniform distribution of servers per request. A request could be assigned to the same dead server several times in a row and wait longer for a valid server or even time out without being processed. Now each query is sent to all servers sequentially in a circle until a response is received or timeout expires. Initial server for each request is still globally balanced.
2016-01-28Resolver: renamed UDP-specific structures, fields and variables.Roman Arutyunyan2-63/+63
They will be used for TCP connections as well.