summaryrefslogtreecommitdiffhomepage
path: root/src/http (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-02-01Cache: fixed race in ngx_http_file_cache_forced_expire().Maxim Dounin1-0/+5
During configuration reload two cache managers might exist for a short time. If both tried to delete the same cache node, the "ignore long locked inactive cache entry" alert appeared in logs. Additionally, ngx_http_file_cache_forced_expire() might be also called by worker processes, with similar results. Fix is to ignore cache nodes being deleted, similarly to how it is done in ngx_http_file_cache_expire() since 3755:76e3a93821b1. This was somehow missed in 7002:ab199f0eb8e8, when ignoring long locked cache entries was introduced in ngx_http_file_cache_forced_expire().
2022-01-31HTTP/3: proper uni stream closure detection.Roman Arutyunyan1-5/+34
Previously, closure detection for server-initiated uni streams was not properly implemented. Instead, HTTP/3 code relied on QUIC code posting the read event and setting rev->error when it needed to close the stream. Then, regular uni stream read handler called c->recv() and received error, which closed the stream. This was an ad-hoc solution. If, for whatever reason, the read handler was called earlier, c->recv() would return 0, which would also close the stream. Now server-initiated uni streams have a separate read event handler for tracking stream closure. The handler calls c->recv(), which normally returns 0, but may return error in case of closure.
2022-01-27HTTP/3: delayed Insert Count Increment instruction.Roman Arutyunyan4-4/+60
Sending the instruction is delayed until the end of the current event cycle. Delaying the instruction is allowed by quic-qpack-21, section 2.2.2.3. The goal is to reduce the amount of data sent back to client by accumulating several inserts in one instruction and sometimes not sending the instruction at all, if Section Acknowledgement was sent just before it.
2022-01-31QUIC: allowed main QUIC connection for some operations.Roman Arutyunyan2-5/+8
Operations like ngx_quic_open_stream(), ngx_http_quic_get_connection(), ngx_http_v3_finalize_connection(), ngx_http_v3_shutdown_connection() used to receive a QUIC stream connection. Now they can receive the main QUIC connection as well. This is useful when calling them from a stream context.
2022-01-26HTTP/3: removed draft versions support in ALPN.Sergey Kandaurov2-18/+0
2022-01-25Merged with the default branch.Sergey Kandaurov1-0/+4
2022-01-18QUIC: the "quic_active_connection_id_limit" directive.Vladimir Homutov1-0/+12
The directive sets corresponding transport parameter and limits number of created client ids.
2022-01-13HTTP/3: removed useless warning regarding OpenSSL library.Sergey Kandaurov1-11/+0
After 0e6528551f26, it became impossible to run into this path.
2022-01-12HTTP/3: set c->error on read error in ngx_http_test_reading().Roman Arutyunyan1-0/+1
Similar to other error/eof cases.
2022-01-12HTTP/3: simplified code.Roman Arutyunyan1-1/+1
2022-01-12QUIC: modified HTTP version test.Roman Arutyunyan1-1/+8
The new condition produces smaller diff to the default branch and is similar to HTTP/2 case.
2022-01-11Avoid sending "Connection: keep-alive" when shutting down.Maxim Dounin1-0/+4
When a worker process is shutting down, keepalive is not used: this is checked before the ngx_http_set_keepalive() call in ngx_http_finalize_connection(). Yet the "Connection: keep-alive" header was still sent, even if we know that the worker process is shutting down, potentially resulting in additional requests being sent to the connection which is going to be closed anyway. While clients are expected to be able to handle asynchronous close events (see ticket #1022), it is certainly possible to send the "Connection: close" header instead, informing the client that the connection is going to be closed and potentially saving some unneeded work. With this change, we additionally check for worker process shutdown just before sending response headers, and disable keepalive accordingly.
2021-12-30HTTP/3: improved processing of multiple Cookie field lines.Sergey Kandaurov2-14/+152
As per draft-ietf-quic-http, 4.1.1.2, and similar to HTTP/2 specification, they ought to be concatenated. This closely follows ngx_http_v2_module.
2021-12-29Style.Roman Arutyunyan1-1/+1
2021-12-29Merged with the default branch.Sergey Kandaurov2-95/+0
2021-12-27Simplified sendfile(SF_NODISKIO) usage.Maxim Dounin1-82/+0
Starting with FreeBSD 11, there is no need to use AIO operations to preload data into cache for sendfile(SF_NODISKIO) to work. Instead, sendfile() handles non-blocking loading data from disk by itself. It still can, however, return EBUSY if a page is already being loaded (for example, by a different process). If this happens, we now post an event for the next event loop iteration, so sendfile() is retried "after a short period", as manpage recommends. The limit of the number of EBUSY tolerated without any progress is preserved, but now it does not result in an alert, since on an idle system event loop iteration might be very short and EBUSY can happen many times in a row. Instead, SF_NODISKIO is simply disabled for one call once the limit is reached. With this change, sendfile(SF_NODISKIO) is now used automatically as long as sendfile() is enabled, and no longer requires "aio on;".
2021-12-27Removed "aio sendfile", deprecated since 1.7.11.Maxim Dounin1-13/+0
2021-12-28Fixed a mismerge in 5c86189a1c1b.Ruslan Ermilov1-0/+2
2021-12-21Moved Huffman coding out of HTTP/2.Ruslan Ermilov7-43/+45
ngx_http_v2_huff_decode.c and ngx_http_v2_huff_encode.c are renamed to ngx_http_huff_decode.c and ngx_http_huff_encode.c.
2021-12-24Merged with the default branch.Ruslan Ermilov12-57/+171
2021-11-25HTTP/2: fixed sendfile() aio handling.Maxim Dounin3-10/+65
With sendfile() in threads ("aio threads; sendfile on;"), client connection can block on writing, waiting for sendfile() to complete. In HTTP/2 this might result in the request hang, since an attempt to continue processing in thread event handler will call request's write event handler, which is usually stopped by ngx_http_v2_send_chain(): it does nothing if there are no additional data and stream->queued is set. Further, HTTP/2 resets stream's c->write->ready to 0 if writing blocks, so just fixing ngx_http_v2_send_chain() is not enough. Can be reproduced with test suite on Linux with: TEST_NGINX_GLOBALS_HTTP="aio threads; sendfile on;" prove h2*.t The following tests currently fail: h2_keepalive.t, h2_priority.t, h2_proxy_max_temp_file_size.t, h2.t, h2_trailers.t. Similarly, sendfile() with AIO preloading on FreeBSD can block as well, with similar results. This is, however, harder to reproduce, especially on modern FreeBSD systems, since sendfile() usually does not return EBUSY. Fix is to modify ngx_http_v2_send_chain() so it actually tries to send data to the main connection when called, and to make sure that c->write->ready is set by the relevant event handlers.
2021-11-25HTTP/2: fixed "task already active" with sendfile in threads.Maxim Dounin2-2/+58
With sendfile in threads, "task already active" alerts might appear in logs if a write event happens on the main HTTP/2 connection, triggering a sendfile in threads while another thread operation is already running. Observed with "aio threads; aio_write on; sendfile on;" and with thread event handlers modified to post a write event to the main HTTP/2 connection (though can happen without any modifications). Similarly, sendfile() with AIO preloading on FreeBSD can trigger duplicate aio operation, resulting in "second aio post" alerts. This is, however, harder to reproduce, especially on modern FreeBSD systems, since sendfile() usually does not return EBUSY. Fix is to avoid starting a sendfile operation if other thread operation is active by checking r->aio in the thread handler (and, similarly, in aio preload handler). The added check also makes duplicate calls protection redundant, so it is removed.
2021-12-09QUIC: fixed e06283038ec8 mis-merge.Sergey Kandaurov1-1/+1
The NGX_HTTP_QUIC macro was removed in 33226ac61076.
2021-12-08HTTP/3: cleanup after "listen .. quic" removal in be08b858086a.Sergey Kandaurov1-1/+0
2021-12-07QUIC: clear SSL_OP_ENABLE_MIDDLEBOX_COMPAT on SSL context switch.Sergey Kandaurov1-0/+8
The SSL_OP_ENABLE_MIDDLEBOX_COMPAT option is provided by QuicTLS and enabled by default in the newly created SSL contexts. SSL_set_quic_method() is used to clear it, which is required for SSL handshake to work on QUIC connections. Switching context in the ngx_http_ssl_servername() SNI callback overrides SSL options from the new SSL context. This results in the option set again. Fix is to explicitly clear it when switching to another SSL context. Initially reported here (in Russian): http://mailman.nginx.org/pipermail/nginx-ru/2021-November/063989.html
2021-12-07HTTP/3: avoid sending stream cancellation for pushed streams.Sergey Kandaurov1-1/+3
2021-12-07HTTP/3: renamed files.Roman Arutyunyan5-8/+8
ngx_http_v3_tables.h and ngx_http_v3_tables.c are renamed to ngx_http_v3_table.h and ngx_http_v3_table.c to better match HTTP/2 code. ngx_http_v3_streams.h and ngx_http_v3_streams.c are renamed to ngx_http_v3_uni.h and ngx_http_v3_uni.c to better match their content.
2021-12-06QUIC: simplified configuration.Vladimir Homutov4-202/+41
Directives that set transport parameters are removed from the configuration. Corresponding values are derived from the quic configuration or initialized to default. Whenever possible, quic configuration parameters are taken from higher-level protocol settings, i.e. HTTP/3.
2021-12-01HTTP/3: $http3 variable.Roman Arutyunyan1-7/+25
A new variable $http3 is added. The variable equals to "h3" for HTTP/3 connections, "hq" for hq connections and is an empty string otherwise. The variable $quic is eliminated. The new variable is similar to $http2 variable.
2021-12-04HTTP/3: http3_hq directive and NGX_HTTP_V3_HQ macro.Roman Arutyunyan8-64/+64
Listen quic parameter is no longer supported.
2021-12-06HTTP/3: merged ngx_http_quic_module into ngx_http_v3_module.Roman Arutyunyan11-653/+579
2021-12-02HTTP/3: adjusted ALPN macro names to align with 61abb35bb8cf.Sergey Kandaurov3-6/+6
2021-11-17HTTP/3: fixed compilation with QUIC, but without HTTP/3.Roman Arutyunyan1-0/+2
2021-11-11QUIC: reject streams which we could not create.Roman Arutyunyan1-0/+3
The reasons why a stream may not be created by server currently include hitting worker_connections limit and memory allocation error. Previously in these cases the entire QUIC connection was closed and all its streams were shut down. Now the new stream is rejected and existing streams continue working. To reject an HTTP/3 request stream, RESET_STREAM and STOP_SENDING with H3_REQUEST_REJECTED error code are sent to client. HTTP/3 uni streams and Stream streams are not rejected.
2021-11-01SSL: $ssl_curve (ticket #2135).Sergey Kandaurov1-0/+3
The variable contains a negotiated curve used for the handshake key exchange process. Known curves are listed by their names, unknown ones are shown in hex. Note that for resumed sessions in TLSv1.2 and older protocols, $ssl_curve contains the curve used during the initial handshake, while in TLSv1.3 it contains the curve used during the session resumption (see the SSL_get_negotiated_group manual page for details). The variable is only meaningful when using OpenSSL 3.0 and above. With older versions the variable is empty.
2021-10-29Changed default value of sendfile_max_chunk to 2m.Maxim Dounin1-1/+1
The "sendfile_max_chunk" directive is important to prevent worker monopolization by fast connections. The 2m value implies maximum 200ms delay with 100 Mbps links, 20ms delay with 1 Gbps links, and 2ms on 10 Gbps links. It also seems to be a good value for disks.
2021-10-29Upstream: sendfile_max_chunk support.Maxim Dounin1-3/+6
Previously, connections to upstream servers used sendfile() if it was enabled, but never honored sendfile_max_chunk. This might result in worker monopolization for a long time if large request bodies are allowed.
2021-10-29Simplified sendfile_max_chunk handling.Maxim Dounin1-5/+1
Previously, it was checked that sendfile_max_chunk was enabled and almost whole sendfile_max_chunk was sent (see e67ef50c3176), to avoid delaying connections where sendfile_max_chunk wasn't reached (for example, when sending responses smaller than sendfile_max_chunk). Now we instead check if there are unsent data, and the connection is still ready for writing. Additionally we also check c->write->delayed to ignore connections already delayed by limit_rate. This approach is believed to be more robust, and correctly handles not only sendfile_max_chunk, but also internal limits of c->send_chain(), such as sendfile() maximum supported length (ticket #1870).
2021-10-29Switched to using posted next events after sendfile_max_chunk.Maxim Dounin1-2/+1
Previously, 1 millisecond delay was used instead. In certain edge cases this might result in noticeable performance degradation though, notably on Linux with typical CONFIG_HZ=250 (so 1ms delay becomes 4ms), sendfile_max_chunk 2m, and link speed above 2.5 Gbps. Using posted next events removes the artificial delay and makes processing fast in all cases.
2021-10-28Mp4: mp4_start_key_frame directive.Roman Arutyunyan1-27/+194
The directive enables including all frames from start time to the most recent key frame in the result. Those frames are removed from presentation timeline using mp4 edit lists. Edit lists are currently supported by popular players and browsers such as Chrome, Safari, QuickTime and ffmpeg. Among those not supporting them properly is Firefox[1]. Based on a patch by Tracey Jaquith, Internet Archive. [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1735300
2021-10-28Mp4: added ngx_http_mp4_update_mdhd_atom() function.Roman Arutyunyan1-8/+32
The function updates the duration field of mdhd atom. Previously it was updated in ngx_http_mp4_read_mdhd_atom(). The change makes it possible to alter track duration as a result of processing track frames.
2021-10-18HTTP/3: send Stream Cancellation instruction.Roman Arutyunyan1-0/+8
As per quic-qpack-21: When a stream is reset or reading is abandoned, the decoder emits a Stream Cancellation instruction. Previously the instruction was not sent. Now it's sent when closing QUIC stream connection if dynamic table capacity is non-zero and eof was not received from client. The latter condition means that a trailers section may still be on its way from client and the stream needs to be cancelled.
2021-10-18HTTP/3: allowed QUIC stream connection reuse.Roman Arutyunyan4-38/+154
A QUIC stream connection is treated as reusable until first bytes of request arrive, which is also when the request object is now allocated. A connection closed as a result of draining, is reset with the error code H3_REQUEST_REJECTED. Such behavior is allowed by quic-http-34: Once a request stream has been opened, the request MAY be cancelled by either endpoint. Clients cancel requests if the response is no longer of interest; servers cancel requests if they are unable to or choose not to respond. When the server cancels a request without performing any application processing, the request is considered "rejected." The server SHOULD abort its response stream with the error code H3_REQUEST_REJECTED. The client can treat requests rejected by the server as though they had never been sent at all, thereby allowing them to be retried later.
2021-10-18HTTP/3: adjusted QUIC connection finalization.Roman Arutyunyan4-30/+82
When an HTTP/3 function returns an error in context of a QUIC stream, it's this function's responsibility now to finalize the entire QUIC connection with the right code, if required. Previously, QUIC connection finalization could be done both outside and inside such functions. The new rule follows a similar rule for logging, leads to cleaner code, and allows to provide more details about the error. While here, a few error cases are no longer treated as fatal and QUIC connection is no longer finalized in these cases. A few other cases now lead to stream reset instead of connection finalization.
2021-11-03QUIC: connections with wrong ALPN protocols are now rejected.Vladimir Homutov1-1/+0
Previously, it was not enforced in the stream module. Now, since b9e02e9b2f1d it is possible to specify protocols. Since ALPN is always required, the 'require_alpn' setting is now obsolete.
2021-11-03Merged with the default branch.Sergey Kandaurov15-131/+266
2021-10-07HTTP/3: traffic-based flood detection.Roman Arutyunyan5-23/+138
With this patch, all traffic over HTTP/3 bidi and uni streams is counted in the h3c->total_bytes field, and payload traffic is counted in the h3c->payload_bytes field. As long as total traffic is many times larger than payload traffic, we consider this to be a flood. Request header traffic is counted as if all fields are literal. Response header traffic is counted as is.
2021-10-06HTTP/3: fixed request length calculation.Roman Arutyunyan1-2/+2
Previously, when request was blocked, r->request_length was not updated.
2021-10-06HTTP/3: removed client-side encoder support.Roman Arutyunyan2-156/+0
Dynamic tables are not used when generating responses anyway.
2021-09-27HTTP/3: reset streams with incomplete responses or timeouts.Roman Arutyunyan1-0/+14
This prevents client from closing the QUIC connection due to response parse error.