Commit Graph

6647 Commits

Author SHA1 Message Date
Roman Arutyunyan 595a642018 QUIC: idle mode for main connection.
Now main QUIC connection for HTTP/3 always has c->idle flag set.  This allows
the connection to receive worker shutdown notification.  It is passed to
application level via a new conf->shutdown() callback.

The HTTP/3 shutdown callback sends GOAWAY to client and gracefully shuts down
the QUIC connection.
2022-10-19 17:45:18 +04:00
Roman Arutyunyan 7cccd64670 HTTP/3: unified hq code with regular HTTP/3 code.
The change removes hq-specific request handler.  Now hq requests are handled
by the HTTP/3 request handler.
2022-10-19 17:45:30 +04:00
Roman Arutyunyan f24d60c54d QUIC: do not send MAX_STREAMS in shutdown state.
No more streams are expected from client.
2022-09-07 13:12:56 +04:00
Roman Arutyunyan 75f37d3fc6 QUIC: defer stream removal until all its data is acked.
Previously, stream was kept alive until all its data is sent.  This resulted
in disabling retransmission of final part of stream when QUIC connection
was closed right after closing stream connection.
2022-08-22 15:33:23 +04:00
Roman Arutyunyan 6949b4b4c2 QUIC: reusable mode for main connection.
The connection is automatically switched to this mode by transport layer when
there are no non-cancelable streams.  Currently, cancelable streams are
HTTP/3 encoder/decoder/control streams.
2022-11-29 17:46:46 +04:00
Roman Arutyunyan fbd48371fe QUIC: post close event for connection close.
Previously, close event was used only for close timeout, while read event was
used for posting connection close.
2022-09-07 19:25:13 +04:00
Roman Arutyunyan 5ae19ab1a5 QUIC: made ngx_quic_finalize_connecion() more graceful.
Previously, ngx_quic_finalize_connection() closed the connection with NGX_ERROR
code, which resulted in immediate connection closure.  Now the code is NGX_OK,
which provides a more graceful shutdown with a timeout.
2022-08-22 15:28:51 +04:00
Roman Arutyunyan be17320c91 QUIC: treat qc->error == -1 as a missing error.
Previously, zero was used for this purpose.  However, NGX_QUIC_ERR_NO_ERROR is
zero too.  As a result, NGX_QUIC_ERR_NO_ERROR was changed to
NGX_QUIC_ERR_INTERNAL_ERROR when closing a QUIC connection.
2022-09-07 12:37:15 +04:00
Sergey Kandaurov 6c843d19f2 QUIC: fixed computation of nonce with packet numbers beyond 2^32.
Prodded by Yu Zhu.
2022-11-25 15:56:33 +04:00
Jiuzhou Cui a7bda07bda HTTP/3: fixed build without NGX_PCRE (broken by 0f5fc7a320db). 2022-11-25 15:07:23 +08:00
Roman Arutyunyan 7702f830dd QUIC: fixed triggering stream read event (ticket #2409).
If a client packet carrying a stream data frame is not acked due to packet loss,
the stream data is retransmitted later by client.  It's also possible that the
retransmitted range is bigger than before due to more stream data being
available by then.  If the original data was read out by the application,
there would be no read event triggered by the retransmitted frame, even though
it contains new data.
2022-11-23 18:50:26 +04:00
Sergey Kandaurov a53a72f079 QUIC: fixed C4334 MSVC warning about 32 to 64 bits conversion. 2022-11-22 18:05:37 +04:00
Sergey Kandaurov 3cf42a4a1d QUIC: plug MSVC warning about potentially uninitialized variable. 2022-11-22 18:05:37 +04:00
Sergey Kandaurov c71b6810be Added shutdown macros for win32 required for QUIC. 2022-11-22 18:05:36 +04:00
Sergey Kandaurov 690e72d8b6 QUIC: fixed C4389 MSVC warning about signed/unsigned mismatch. 2022-11-22 18:05:36 +04:00
Sergey Kandaurov 41a5fad87b QUIC: avoid using C99 designated initializers.
They are not supported by MSVC till 2012.

SSL_QUIC_METHOD initialization is moved to run-time to preserve portability
among SSL library implementations, which allows to reduce its visibility.
Note using of a static storage to keep SSL_set_quic_method() reference valid.
2022-11-22 18:05:35 +04:00
Sergey Kandaurov 8e422fd5e8 QUIC: moved variable declaration to fix build with MSVC 2010.
Previously, ngx_quic_hkdf_t variables used declaration with assignment
in the middle of a function, which is not supported by MSVC 2010.
Fixing this also required to rewrite the ngx_quic_hkdf_set macro
and to switch to an explicit array size.
2022-11-22 18:05:35 +04:00
Sergey Kandaurov 5a00ab5877 QUIC: fixed C4706 warnings with MSVC 2010.
The fix is to avoid assignments within conditional expression.
2022-11-22 18:05:34 +04:00
Sergey Kandaurov 4d1689d053 HTTP/3: fixed server_name regex captures (ticket #2407).
Previously, HTTP/3 stream connection didn't inherit the servername regex
from the main QUIC connection saved when processing SNI and using regular
expressions in server names.  As a result, it didn't execute to set regex
captures when choosing the virtual server while parsing HTTP/3 headers.
2022-11-22 14:10:04 +04:00
Roman Arutyunyan 0854b8073f Set default listen socket type in http.
The type field was added in 7999d3fbb765 at early stages of QUIC implementation
and was not initialized for default listen.  Missing initialization resulted in
default listen socket creation error.
2022-11-01 17:00:35 +04:00
Sergey Kandaurov de23dc786b Merged with the default branch. 2022-10-20 16:41:36 +04:00
Sergey Kandaurov 993631dea7 QUIC: removed compatibility with older BoringSSL API.
SSL_CIPHER_get_protocol_id() appeared in BoringSSL somewhere between
BORINGSSL_API_VERSION 12 and 13 for compatibility with OpenSSL 1.1.1.
It was adopted without a proper macro test, which remained unnoticed.
This justifies that such old BoringSSL API isn't widely used and its
support can be dropped.

While here, removed SSL_set_quic_use_legacy_codepoint() that became
useless after the default was flipped in BoringSSL over a year ago.
2022-10-20 16:21:07 +04:00
Sergey Kandaurov d0bd68de53 QUIC: support for setting QUIC methods with LibreSSL.
Setting QUIC methods is converted to use C99 designated initializers
for simplicity, as LibreSSL 3.6.0 has different SSL_QUIC_METHOD layout.

Additionally, only set_read_secret/set_write_secret callbacks are set.
Although they are preferred in LibreSSL over set_encryption_secrets,
better be on a safe side as LibreSSL has unexpectedly incompatible
set_encryption_secrets calling convention expressed in passing read
and write secrets split in separate calls, unlike this is documented
in old BoringSSL sources.  To avoid introducing further changes for
the old API, it is simply disabled.
2022-10-20 16:21:06 +04:00
Sergey Kandaurov e5ebf25fcc QUIC: using SSL_set_quic_early_data_enabled() only with QuicTLS.
This function is present in QuicTLS only.  After SSL_READ_EARLY_DATA_SUCCESS
became visible in LibreSSL together with experimental QUIC API, this required
to revise the conditional compilation test to use more narrow macros.
2022-10-20 16:21:06 +04:00
Sergey Kandaurov 6b7d3d64c3 QUIC: using native TLSv1.3 cipher suite constants.
After BoringSSL aligned[1] with OpenSSL on TLS1_3_CK_* macros, and
LibreSSL uses OpenSSL naming, our own variants can be dropped now.
Compatibility is preserved with libraries that lack these macros.

Additionally, transition to SSL_CIPHER_get_id() fixes build error
with LibreSSL that doesn't implement SSL_CIPHER_get_protocol_id().

[1] https://boringssl.googlesource.com/boringssl/+/dfddbc4ded
2022-10-20 16:21:05 +04:00
Sergey Kandaurov 03a1a94d18 QUIC: "info" logging level on insufficient client connection ids.
Apparently, this error is reported on NAT rebinding if client didn't
previously send NEW_CONNECTION_ID to supply additional connection ids.
2022-09-30 17:24:47 +04:00
Murilo Andrade 9e68d2296f SSL: logging level of "bad record type" errors.
The SSL_R_BAD_RECORD_TYPE ("bad record type") errors are reported by
OpenSSL 1.1.1 or newer when using TLSv1.3 if the client sends a record
with unknown or unexpected type.  These errors are now logged at the
"info" level.
2022-08-09 17:13:46 -03:00
Maxim Dounin 4dfce3ca3c Version bump. 2022-08-30 01:52:51 +03:00
Roman Arutyunyan 2d72193dc0 HTTP/3: skip empty request body buffers (ticket #2374).
When client DATA frame header and its content come in different QUIC packets,
it may happen that only the header is processed by the first
ngx_http_v3_request_body_filter() call.  In this case an empty request body
buffer is added to r->request_body->bufs, which is later reused in a
subsequent ngx_http_v3_request_body_filter() call without being removed from
the body chain.  As a result, rb->request_body->bufs ends up with two copies of
the same buffer.

The fix is to avoid adding empty request body buffers to r->request_body->bufs.
2022-08-03 16:59:51 +04:00
Maxim Dounin b585c3b74e Events: fixed EPOLLRDHUP with FIONREAD (ticket #2367).
When reading exactly rev->available bytes, rev->available might become 0
after FIONREAD usage introduction in efd71d49bde0.  On the next call of
ngx_readv_chain() on systems with EPOLLRDHUP this resulted in return without
any actions, that is, with rev->ready set, and this in turn resulted in no
timers set in event pipe, leading to socket leaks.

Fix is to reset rev->ready in ngx_readv_chain() when returning due to
rev->available being 0 with EPOLLRDHUP, much like it is already done in
ngx_unix_recv().  This ensures that if rev->available will become 0, on
systems with EPOLLRDHUP support appropriate EPOLLRDHUP-specific handling
will happen on the next ngx_readv_chain() call.

While here, also synced ngx_readv_chain() to match ngx_unix_recv() and
reset rev->ready when returning due to rev->available being 0 with kqueue.
This is mostly cosmetic change, as rev->ready is anyway reset when
rev->available is set to 0.
2022-07-15 15:19:32 +03:00
Maxim Dounin ce67cac0ba Range filter: clearing of pre-existing Content-Range headers.
Some servers might emit Content-Range header on 200 responses, and this
does not seem to contradict RFC 9110: as per RFC 9110, the Content-Range
header has no meaning for status codes other than 206 and 416.  Previously
this resulted in duplicate Content-Range headers in nginx responses handled
by the range filter.  Fix is to clear pre-existing headers.
2022-07-15 07:01:44 +03:00
Sergey Kandaurov ec2ecdd62b Resolver: fixed memory leak for the "ipv4=off" case.
This change partially reverts 2a77754cd9fe to properly free rn->query.

Found by Coverity (CID 1507244).
2022-07-14 21:26:54 +04:00
Ruslan Ermilov bcf1402445 The "ipv4=" parameter of the "resolver" directive.
When set to "off", only IPv6 addresses will be resolved, and no
A queries are ever sent (ticket #2196).
2022-07-12 21:44:02 +04:00
Maxim Dounin f94e5b01a7 SSL: logging levels of various errors added in OpenSSL 1.1.1.
Starting with OpenSSL 1.1.1, various additional errors can be reported
by OpenSSL in case of client-related issues, most notably during TLSv1.3
handshakes.  In particular, SSL_R_BAD_KEY_SHARE ("bad key share"),
SSL_R_BAD_EXTENSION ("bad extension"), SSL_R_BAD_CIPHER ("bad cipher"),
SSL_R_BAD_ECPOINT ("bad ecpoint").  These are now logged at the "info"
level.
2022-07-12 15:55:22 +03:00
Maxim Dounin 86fa8882c8 Upstream: optimized use of SSL contexts (ticket #1234).
To ensure optimal use of memory, SSL contexts for proxying are now
inherited from previous levels as long as relevant proxy_ssl_* directives
are not redefined.

Further, when no proxy_ssl_* directives are redefined in a server block,
we now preserve plcf->upstream.ssl in the "http" section configuration
to inherit it to all servers.

Similar changes made in uwsgi, grpc, and stream proxy.
2022-06-29 02:47:45 +03:00
Maxim Dounin ef4919f875 Version bump. 2022-06-29 02:47:38 +03:00
Sergey Kandaurov 9912eb8939 Perl: removed unused variables, forgotten in ef6a3a99a81a. 2022-06-14 10:39:58 +04:00
Aleksei Bavshin b29e4652bb Resolver: make TCP write timer event cancelable.
Similar to 70e65bf8dfd7, the change is made to ensure that the ability to
cancel resolver tasks is fully controlled by the caller.  As mentioned in the
referenced commit, it is safe to make this timer cancelable because resolve
tasks can have their own timeouts that are not cancelable.

The scenario where this may become a problem is a periodic background resolve
task (not tied to a specific request or a client connection), which receives a
response with short TTL, large enough to warrant fallback to a TCP query.
With each event loop wakeup, we either have a previously set write timer
instance or schedule a new one.  The non-cancelable write timer can delay or
block graceful shutdown of a worker even if the ngx_resolver_ctx_t->cancelable
flag is set by the API user, and there are no other tasks or connections.

We use the resolver API in this way to maintain the list of upstream server
addresses specified with the 'resolve' parameter, and there could be third-party
modules implementing similar logic.
2022-06-01 20:17:23 -07:00
Vladimir Homutov d3d5a9b8a4 QUIC: avoided pool usage in token calculation. 2022-05-31 11:05:22 +04:00
Vladimir Homutov fe6cac822c QUIC: removed ngx_quic_keys_new().
The ngx_quic_keys_t structure is now exposed.
2022-07-27 17:31:16 +04:00
Vladimir Homutov da18efff87 QUIC: avoided pool usage in ngx_quic_protection.c. 2022-07-27 17:16:40 +04:00
Vladimir Homutov 17c9506b58 QUIC: fixed-length buffers for secrets. 2022-07-27 17:15:33 +04:00
Sergey Kandaurov 03b740ba06 Merged with the default branch. 2022-07-26 19:54:11 +04:00
Sergey Kandaurov f2bc2e05d0 Merged with the default branch. 2022-06-22 18:34:58 +04:00
Sergey Kandaurov 658e350aae HTTP/3: updated SETTINGS_MAX_FIELD_SECTION_SIZE name. 2022-06-08 16:19:01 +04:00
Roman Arutyunyan b752b1ec26 HTTP/3: require that field section base index is not negative.
RFC 9204 explicitly requires that.
2022-05-26 16:17:56 +04:00
Aleksei Bavshin 663445ba7a Stream: don't flush empty buffers created for read errors.
When we generate the last_buf buffer for an UDP upstream recv error, it does
not contain any data from the wire. ngx_stream_write_filter attempts to forward
it anyways, which is incorrect (e.g., UDP upstream ECONNREFUSED will be
translated to an empty packet).

This happens because we mark the buffer as both 'flush' and 'last_buf', and
ngx_stream_write_filter has special handling for flush with certain types of
connections (see d127837c714f, 32b0ba4855a6).  The flags are meant to be
mutually exclusive, so the fix is to ensure that flush and last_buf are not set
at the same time.

Reproduction:

stream {
    upstream unreachable {
        server     127.0.0.1:8880;
    }
    server {
        listen     127.0.0.1:8998 udp;
        proxy_pass unreachable;
    }
}

1 0.000000000    127.0.0.1 → 127.0.0.1    UDP 47 45588 → 8998 Len=5
2 0.000166300    127.0.0.1 → 127.0.0.1    UDP 47 51149 → 8880 Len=5
3 0.000172600    127.0.0.1 → 127.0.0.1    ICMP 75 Destination unreachable (Port
unreachable)
4 0.000202400    127.0.0.1 → 127.0.0.1    UDP 42 8998 → 45588 Len=0

Fixes d127837c714f.
2022-05-23 11:29:44 -07:00
Maxim Dounin 8d3f47c131 Mp4: fixed potential overflow in ngx_http_mp4_crop_stts_data().
Both "count" and "duration" variables are 32-bit, so their product might
potentially overflow.  It is used to reduce 64-bit start_time variable,
and with very large start_time this can result in incorrect seeking.

Found by Coverity (CID 1499904).
2022-06-07 21:58:52 +03:00
Sergey Kandaurov 82ff3c2d8c Upstream: handling of certificates specified as an empty string.
Now, if the directive is given an empty string, such configuration cancels
loading of certificates, in particular, if they would be otherwise inherited
from the previous level.  This restores previous behaviour, before variables
support in certificates was introduced (3ab8e1e2f0f7).
2022-06-07 20:08:57 +04:00
Maxim Dounin bb4d3b091d Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Previously, if caching was disabled due to Expires in the past, nginx
failed to cache the response even if it was cacheable as per subsequently
parsed Cache-Control header (ticket #964).

Similarly, if caching was disabled due to Expires in the past,
"Cache-Control: no-cache" or "Cache-Control: max-age=0", caching was not
used if it was cacheable as per subsequently parsed X-Accel-Expires header.

Fix is to avoid disabling caching immediately after parsing Expires in
the past or Cache-Control, but rather set flags which are later checked by
ngx_http_upstream_process_headers() (and cleared by "Cache-Control: max-age"
and X-Accel-Expires).

Additionally, now X-Accel-Expires does not prevent parsing of cache control
extensions, notably stale-while-revalidate and stale-if-error.  This
ensures that order of the X-Accel-Expires and Cache-Control headers is not
important.

Prodded by Vadim Fedorenko and Yugo Horie.
2022-06-07 00:07:12 +03:00
Maxim Dounin e571a75ba4 Upstream: fixed build without http cache (broken by cd73509f21e2). 2022-05-31 00:14:11 +03:00
Maxim Dounin 7ec70432d4 Headers filter: improved memory allocation error handling. 2022-05-30 21:25:57 +03:00
Maxim Dounin c43e768c74 Multiple WWW-Authenticate headers with "satisfy any;".
If a module adds multiple WWW-Authenticate headers (ticket #485) to the
response, linked in r->headers_out.www_authenticate, all headers are now
cleared if another module later allows access.

This change is a nop for standard modules, since the only access module which
can add multiple WWW-Authenticate headers is the auth request module, and
it is checked after other standard access modules.  Though this might
affect some third party access modules.

Note that if a 3rd party module adds a single WWW-Authenticate header
and not yet modified to set the header's next pointer to NULL, attempt to
clear such a header with this change will result in a segmentation fault.
2022-05-30 21:25:56 +03:00
Maxim Dounin ac4d19865a Auth request: multiple WWW-Authenticate headers (ticket #485).
When using auth_request with an upstream server which returns 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.
2022-05-30 21:25:54 +03:00
Maxim Dounin 3d731d9748 Upstream: multiple WWW-Authenticate headers (ticket #485).
When using proxy_intercept_errors and an error page for error 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.
2022-05-30 21:25:53 +03:00
Maxim Dounin 12bd0b0884 Upstream: handling of multiple Vary headers (ticket #1423).
Previously, only the last header value was used when caching.
2022-05-30 21:25:51 +03:00
Maxim Dounin 027b46b7ea Upstream: duplicate headers ignored or properly linked.
Most of the known duplicate upstream response headers are now ignored
with a warning.

If syntax permits multiple headers, these are now properly linked to
the lists, notably Vary and WWW-Authenticate.  This makes it possible
to further handle such lists where it makes sense.
2022-05-30 21:25:49 +03:00
Maxim Dounin 47e9ce390d Upstream: header handlers can now return parsing errors.
With this change, duplicate Content-Length and Transfer-Encoding headers
are now rejected.  Further, responses with invalid Content-Length or
Transfer-Encoding headers are now rejected, as well as responses with both
Content-Length and Transfer-Encoding.
2022-05-30 21:25:48 +03:00
Maxim Dounin 4e5ce1fa2e Upstream: all known headers in u->headers_in are linked lists now. 2022-05-30 21:25:46 +03:00
Maxim Dounin dd06c6b586 All known output headers can be linked lists now.
The h->next pointer properly provided as NULL in all cases where known
output headers are added.

Note that there are 3rd party modules which might not do this, and it
might be risky to rely on this for arbitrary headers.
2022-05-30 21:25:45 +03:00
Maxim Dounin 95ec5e3d95 Upstream: simplified Accept-Ranges handling.
The u->headers_in.accept_ranges field is not used anywhere and hence removed.
2022-05-30 21:25:43 +03:00
Maxim Dounin f77cf83837 Upstream: simplified Content-Encoding handling.
Since introduction of offset handling in ngx_http_upstream_copy_header_line()
in revision 573:58475592100c, the ngx_http_upstream_copy_content_encoding()
function is no longer needed, as its behaviour is exactly equivalent to
ngx_http_upstream_copy_header_line() with appropriate offset.  As such,
the ngx_http_upstream_copy_content_encoding() function was removed.

Further, the u->headers_in.content_encoding field is not used anywhere,
so it was removed as well.

Further, Content-Encoding handling no longer depends on NGX_HTTP_GZIP,
as it can be used even without any gzip handling compiled in (for example,
in the charset filter).
2022-05-30 21:25:42 +03:00
Maxim Dounin e1778b75f3 Upstream: style. 2022-05-30 21:25:40 +03:00
Maxim Dounin bf8acaa78a Perl: combining unknown headers during $r->header_in() lookup. 2022-05-30 21:25:38 +03:00
Maxim Dounin 7de2b91556 Perl: all known input headers are handled identically.
As all known input headers are now linked lists, these are now handled
identically.  In particular, this makes it possible to access properly
combined values of headers not specifically handled previously, such
as "Via" or "Connection".
2022-05-30 21:25:36 +03:00
Maxim Dounin 0c2a0ef934 All non-unique input headers are now linked lists.
The ngx_http_process_multi_header_lines() function is removed, as it is
exactly equivalent to ngx_http_process_header_line().  Similarly,
ngx_http_variable_header() is used instead of ngx_http_variable_headers().
2022-05-30 21:25:35 +03:00
Maxim Dounin 29a1e8e317 Reworked multi headers to use linked lists.
Multi headers are now using linked lists instead of arrays.  Notably,
the following fields were changed: r->headers_in.cookies (renamed
to r->headers_in.cookie), r->headers_in.x_forwarded_for,
r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control
u->headers_in.cookies (renamed to u->headers_in.set_cookie).

The r->headers_in.cookies and u->headers_in.cookies fields were renamed
to r->headers_in.cookie and u->headers_in.set_cookie to match header names.

The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines()
functions were changed accordingly.

With this change, multi headers are now essentially equivalent to normal
headers, and following changes will further make them equivalent.
2022-05-30 21:25:33 +03:00
Maxim Dounin ad8f9f7411 Combining unknown headers during variables lookup (ticket #1316).
Previously, $http_*, $sent_http_*, $sent_trailer_*, $upstream_http_*,
and $upstream_trailer_* variables returned only the first header (with
a few specially handled exceptions: $http_cookie, $http_x_forwarded_for,
$sent_http_cache_control, $sent_http_link).

With this change, all headers are returned, combined together.  For
example, $http_foo variable will be "a, b" if there are "Foo: a" and
"Foo: b" headers in the request.

Note that $upstream_http_set_cookie will also return all "Set-Cookie"
headers (ticket #1843), though this might not be what one want, since
the "Set-Cookie" header does not follow the list syntax (see RFC 7230,
section 3.2.2).
2022-05-30 21:25:32 +03:00
Maxim Dounin f6087d2731 Uwsgi: combining headers with identical names (ticket #1724).
The uwsgi specification states that "The uwsgi block vars represent a
dictionary/hash".  This implies that no duplicate headers are expected.

Further, provided headers are expected to follow CGI specification,
which also requires to combine headers (RFC 3875, section "4.1.18.
Protocol-Specific Meta-Variables"): "If multiple header fields with
the same field-name are received then the server MUST rewrite them
as a single value having the same semantics".
2022-05-30 21:25:30 +03:00
Maxim Dounin d86b7da869 SCGI: combining headers with identical names (ticket #1724).
SCGI specification explicitly forbids headers with duplicate names
(section "3. Request Format"): "Duplicate names are not allowed in
the headers".

Further, provided headers are expected to follow CGI specification,
which also requires to combine headers (RFC 3875, section "4.1.18.
Protocol-Specific Meta-Variables"): "If multiple header fields with
the same field-name are received then the server MUST rewrite them
as a single value having the same semantics".
2022-05-30 21:25:28 +03:00
Maxim Dounin 189568930e FastCGI: combining headers with identical names (ticket #1724).
FastCGI responder is expected to receive CGI/1.1 environment variables
in the parameters (see section "6.2 Responder" of the FastCGI specification).
Obviously enough, there cannot be multiple environment variables with
the same name.

Further, CGI specification (RFC 3875, section "4.1.18. Protocol-Specific
Meta-Variables") explicitly requires to combine headers: "If multiple
header fields with the same field-name are received then the server MUST
rewrite them as a single value having the same semantics".
2022-05-30 21:25:27 +03:00
Maxim Dounin 021a3fbc4e Perl: fixed $r->header_in("Connection").
Previously, the r->header_in->connection pointer was never set despite
being present in ngx_http_headers_in, resulting in incorrect value returned
by $r->header_in("Connection") in embedded perl.
2022-05-30 21:25:25 +03:00
Marcus Ball 01ca68ac56 Fixed runtime handling of systems without EPOLLRDHUP support.
In 7583:efd71d49bde0 (nginx 1.17.5) along with introduction of the
ioctl(FIONREAD) support proper handling of systems without EPOLLRDHUP
support in the kernel (but with EPOLLRDHUP in headers) was broken.

Before the change, rev->available was never set to 0 unless
ngx_use_epoll_rdhup was also set (that is, runtime test for EPOLLRDHUP
introduced in 6536:f7849bfb6d21 succeeded).  After the change,
rev->available might reach 0 on systems without runtime EPOLLRDHUP
support, stopping further reading in ngx_readv_chain() and ngx_unix_recv().
And, if EOF happened to be already reported along with the last event,
it is not reported again by epoll_wait(), leading to connection hangs
and timeouts on such systems.

This affects Linux kernels before 2.6.17 if nginx was compiled
with newer headers, and, more importantly, emulation layers, such as
DigitalOcean's App Platform's / gVisor's epoll emulation layer.

Fix is to explicitly check ngx_use_epoll_rdhup before the corresponding
rev->pending_eof tests in ngx_readv_chain() and ngx_unix_recv().
2022-05-30 02:38:07 +03:00
Maxim Dounin 8e2a2eca0b Version bump. 2022-05-30 02:37:59 +03:00
Roman Arutyunyan 86a3380000 QUIC: separate UDP framework for QUIC.
Previously, QUIC used the existing UDP framework, which was created for UDP in
Stream.  However the way QUIC connections are created and looked up is different
from the way UDP connections in Stream are created and looked up.  Now these
two implementations are decoupled.
2022-04-20 16:01:17 +04:00
Roman Arutyunyan c5f5a571d9 QUIC: fixed insertion at the end of buffer.
Previously, last buffer was tracked by keeping a pointer to the previous
chain link "next" field.  When the previous buffer was split and then removed,
the pointer was no longer valid.  Writing at this pointer resulted in broken
data chains.

Now last buffer is tracked by keeping a direct pointer to it.
2022-02-17 22:38:42 +03:00
Sergey Kandaurov 4ce2114724 QUIC: fixed indentation. 2022-02-16 15:45:47 +03:00
Roman Arutyunyan 418ce3b294 QUIC: optimize insertion at the end of QUIC buffer. 2022-02-14 14:54:34 +03:00
Roman Arutyunyan ab1adbbc08 QUIC: eliminated ngx_quic_copy_buf().
Its only call is substituted with QUIC buffer write/read pair.
2022-02-14 14:53:46 +03:00
Roman Arutyunyan 45c5af421b QUIC: trim input chain in ngx_quic_buffer_write().
This allows to eliminate explicit trimming when handling input STREAM frame.
As a result, ngx_quic_trim_chain() is eliminated as well.
2022-02-14 14:51:10 +03:00
Roman Arutyunyan 8363d84edd QUIC: ngx_quic_buffer_t object.
The object is used instead of ngx_chain_t pointer for buffer operations like
ngx_quic_write_chain() and ngx_quic_read_chain().  These functions are renamed
to ngx_quic_write_buffer() and ngx_quic_read_buffer().
2022-02-14 15:27:59 +03:00
Sergey Kandaurov 8c4e29e4f0 SSL: logging level of "application data after close notify".
Such fatal errors are reported by OpenSSL 1.1.1, and similarly by BoringSSL,
if application data is encountered during SSL shutdown, which started to be
observed on the second SSL_shutdown() call after SSL shutdown fixes made in
09fb2135a589 (1.19.2).  The error means that the client continues to send
application data after receiving the "close_notify" alert (ticket #2318).
Previously it was reported as SSL_shutdown() error of SSL_ERROR_SYSCALL.
2022-02-08 17:35:27 +03:00
Roman Arutyunyan 28919d3e59 QUIC: stream lingering.
Now ngx_quic_stream_t is decoupled from ngx_connection_t in a way that it
can persist after connection is closed by application.  During this period,
server is expecting stream final size from client for correct flow control.
Also, buffered output is sent to client as more flow control credit is granted.
2022-02-05 12:54:54 +03:00
Sergey Kandaurov 6e67500606 QUIC: optimized datagram expansion with half-RTT tickets.
As shown in RFC 8446, section 2.2, Figure 3, and further specified in
section 4.6.1, BoringSSL releases session tickets in Application Data
(along with Finished) early, based on a precalculated client Finished
transcript, once client signalled early data in extensions.
2022-02-15 14:12:34 +03:00
Sergey Kandaurov 45e76acd51 Merged with the default branch. 2022-02-14 10:14:07 +03:00
Vladimir Homutov d261bc2b0b QUIC: fixed in-flight bytes accounting.
Initially, frames are genereated and stored in ctx->frames.
Next, ngx_quic_output() collects frames to be sent in in ctx->sending.
On failure, ngx_quic_revert_sned() returns frames into ctx->frames.

On success, the ngx_quic_commit_send() moves ack-eliciting frames into
ctx->sent and frees non-ack-eliciting frames.
This function also updates in-flight bytes counter, so only actually sent
frames are accounted.

The counter is decremented in the following cases:
 - acknowledgment is received
 - packet was declared lost
 - we are discarding context completely

In each of this cases frame is removed from ctx->sent queue and in-flight
counter is accordingly decremented.

The patch fixes the case of discarding context - only removing frames
from ctx->sent must be followed by in-flight bytes counter decrement,
otherwise cg->in_flight could experience type underflow.

The issue appeared in b1676cd64dc9.
2022-02-09 15:51:42 +03:00
Vladimir Homutov 615dbe6b64 QUIC: fixed output context restoring.
The cd8018bc81a5 fixed unintended send of non-padded initial packets,
but failed to restore context properly: only processed contexts need
to be restored.  As a consequence, a packet number could be restored
from uninitialized value.
2022-02-09 15:53:21 +03:00
Roman Arutyunyan 6920deb708 QUIC: fixed resetting stream wev->ready flag.
Previously, the flag could be reset after send_chain() with a limit, even
though there was room for more data.  The application then started waiting for
a write event notification, which never happened.

Now the wev->ready flag is only reset when flow control is exhausted.
2022-02-09 14:49:05 +03:00
Vladimir Homutov e2b85c16d0 QUIC: fixed the "quic_stream_buffer_size" directive.
The default value is now correctly set and the configuration
is properly merged.
2022-02-08 23:00:12 +03:00
Maxim Dounin 807b009133 HTTP/2: fixed closed_nodes overflow (ticket #1708).
With large http2_max_concurrent_streams or http2_max_concurrent_pushes, more
than 255 ngx_http_v2_node_t structures might be allocated, eventually leading
to h2c->closed_nodes overflow when closing corresponding streams.  This will
in turn result in additional allocations in ngx_http_v2_get_node_by_id().

While mostly harmless, it can result in excessive memory usage by a HTTP/2
connection, notably in configurations with many keepalive_requests allowed.
Fix is to use ngx_uint_t for h2c->closed_nodes instead of unsigned:8.
2022-02-03 22:46:01 +03:00
Roman Arutyunyan 2ddbea69f1 QUIC: switch stream to DATA_RECVD state.
The switch happens when received byte counter reaches stream final size.
Previously, this state was skipped.  The stream went from SIZE_KNOWN to
DATA_READ when all bytes were read by application.

The change prevents STOP_SENDING frames from being sent when all data is
received from client, but not yet fully read by application.
2022-02-03 18:11:59 +03:00
Roman Arutyunyan 89b9a30c3c QUIC: improved size calculation in ngx_quic_write_chain().
Previously, size was calculated based on the number of input bytes processed
by the function.  Now only the copied bytes are considered.  This prevents
overlapping buffers from contributing twice to the overall written size.
2022-02-03 21:29:05 +03:00
Maxim Dounin 4cdfb1ee3c HTTP/2: made it possible to flush response headers (ticket #1743).
Response headers can be buffered in the SSL buffer.  But stream's fake
connection buffered flag did not reflect this, so any attempts to flush
the buffer without sending additional data were stopped by the write filter.

It does not seem to be possible to reflect this in fc->buffered though, as
we never known if main connection's c->buffered corresponds to the particular
stream or not.  As such, fc->buffered might prevent request finalization
due to sending data on some other stream.

Fix is to implement handling of flush buffers when the c->need_flush_buf
flag is set, similarly to the existing last buffer handling.  The same
flag is now used for UDP sockets in the stream module instead of explicit
checking of c->type.
2022-02-03 01:44:38 +03:00
Sergey Kandaurov 2e7f031ba8 QUIC: do not arm loss detection timer if nothing was sent.
Notably, this became quite practicable after the recent fix in cd8018bc81a5.

Additionally, do not arm loss detection timer on connection termination.
2022-02-02 15:57:08 +03:00
Vladimir Homutov 144c6f6aa7 QUIC: fixed padding of initial packets in case of limited path.
Previously, non-padded initial packet could be sent as a result of the
following situation:

 - initial queue is not empty (so padding to 1200 is required)
 - handshake queue is not empty (so padding is to be added after h/s packet)
 - path is limited

If serializing handshake packet would violate path limit, such packet was
omitted, and the non-padded initial packet was sent.

The fix is to avoid sending the packet at all in such case.  This follows the
original intention introduced in c5155a0cb12f.
2022-02-02 14:16:48 +03:00
Sergey Kandaurov afe8ad39f0 QUIC: do not declare SSL buffering, it's not used.
No functional changes.
2022-02-01 20:46:32 +03:00
Maxim Dounin cfd713832d Cache: fixed race in ngx_http_file_cache_forced_expire().
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-02-01 16:29:28 +03:00
Vladimir Homutov e16352881a QUIC: improved debug logging.
- wording in log->action is adjusted to match function names.

 - connection close steps are made obvious and start with "quic close" prefix:
     *1 quic close initiated rc:-4
     *1 quic close silent drain:0 timedout:1
     *1 quic close resumed rc:-1
     *1 quic close resumed rc:-1
     *1 quic close resumed rc:-4
     *1 quic close completed

   this makes it easy to understand if particular "close" record is an initial
   cause or lasting process, or the final one.

 - cases of close without quic connection now logged as "packet rejected":
     *14 quic run
     *14 quic packet rx long flags:ec version:1
     *14 quic packet rx hs len:61
     *14 quic packet rx dcid len:20 00000000000002c32f60e4aa2b90a64a39dc4228
     *14 quic packet rx scid len:8 81190308612cd019
     *14 quic expected initial, got handshake
     *14 quic packet done rc:-1 level:hs decr:0 pn:0 perr:0
     *14 quic packet rejected rc:-1, cleanup connection
     *14 reusable connection: 0

   this makes it easy to spot early packet rejection and avoid confuse with
   quic connection closing (which in fact was not even created).

 - packet processing summary now uses same prefix "quic packet done rc:"

 - added debug to places where packet was rejected without any reason logged
2022-02-01 15:43:56 +03:00
Vladimir Homutov bda9e27f29 QUIC: got rid of hash symbol in backup and logging.
Now all objectes with sequence number (i.e. sockets, connection ids and
paths) are logged as "foo seq:N".
2022-01-28 14:57:33 +03:00
Vladimir Homutov 4f37d2d295 QUIC: dead code removed.
The ngx_quic_parse_packet() now returns NGX_OK, NGX_ERROR (parsing failed)
and NGX_ABORT (unsupported version).
2022-02-01 13:01:10 +03:00
Vladimir Homutov 2e249af96e QUIC: merged ngx_quic_close_quic() and ngx_quic_close_connection().
The separate ngx_quic_close_quic() doesn't make much sense.
2022-02-01 13:05:38 +03:00
Vladimir Homutov 03fa9875a6 QUIC: revised ngx_quic_handle_datagram() error codes.
The NGX_DECLINED is replaced with NGX_DONE to match closer to return code
of ngx_quic_handle_packet() and ngx_quic_close_connection() rc argument.

The ngx_quic_close_connection() rc code is used only when quic connection
exists, thus anything goes if qc == NULL.

The ngx_quic_handle_datagram() does not return NG_OK in cases when quic
connection is not yet created.
2022-02-01 14:35:31 +03:00
Vladimir Homutov 32e84e9b4a Core: added autotest for UDP segmentation offloading. 2022-01-26 20:40:00 +03:00
Roman Arutyunyan 0b7051b4f3 QUIC: stream event setting function.
The function ngx_quic_set_event() is now called instead of posting events
directly.
2022-01-26 12:01:31 +03:00
Roman Arutyunyan b97e7a75a7 QUIC: style. 2022-01-31 18:09:03 +03:00
Roman Arutyunyan c2e9c35718 HTTP/3: proper uni stream closure detection.
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-31 09:46:30 +03:00
Roman Arutyunyan 6e7c3ad42c QUIC: introduced explicit stream states.
This allows to eliminate the usage of stream connection event flags for tracking
stream state.
2022-01-31 09:46:02 +03:00
Roman Arutyunyan 6850f6e935 HTTP/3: delayed Insert Count Increment instruction.
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-27 12:20:47 +03:00
Roman Arutyunyan d503544196 QUIC: allowed main QUIC connection for some operations.
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-31 09:16:47 +03:00
Sergey Kandaurov 1d39bb83db QUIC: limited SSL_set_quic_use_legacy_codepoint() API usage.
As advertised in BoringSSL a1d3bfb64fd7ef2cb178b5b515522ffd75d7b8c5,
it may be dropped once callers implementing the draft versions cycle out.
2022-01-27 13:14:01 +03:00
Roman Arutyunyan 1e056aced9 QUIC: style. 2022-01-26 18:03:45 +03:00
Vladimir Homutov b3fd447923 QUIC: fixed handling of initial source connection id.
This was broken in 1e2f4e9c8195.

While there, adjusted formatting of debug message with socket seqnum.
2022-01-26 15:48:12 +03:00
Sergey Kandaurov fcf955fdf8 QUIC: set to standard TLS codepoint after draft versions removal.
This is to ease transition with oldish BoringSSL versions,
the default for SSL_set_quic_use_legacy_codepoint() has been
flipped in BoringSSL a1d3bfb64fd7ef2cb178b5b515522ffd75d7b8c5.
2022-01-26 14:15:40 +03:00
Sergey Kandaurov d1b929cc71 QUIC: removed draft versions support. 2022-01-26 14:15:40 +03:00
Sergey Kandaurov 6c4bd8acd6 HTTP/3: removed draft versions support in ALPN. 2022-01-26 14:15:40 +03:00
Vladimir Homutov bb42e87e67 Core: added function for local source address cmsg. 2022-01-25 15:48:58 +03:00
Vladimir Homutov 906d7f354f Core: made the ngx_sendmsg() function non-static.
The NGX_HAVE_ADDRINFO_CMSG macro is defined when at least one of methods
to deal with corresponding control message is available.
2022-01-25 15:48:56 +03:00
Vladimir Homutov 4c658c3465 Core: the ngx_event_udp.h header file. 2022-01-25 15:41:48 +03:00
Vladimir Homutov b1e646b1bf Version bump. 2022-01-27 13:44:09 +03:00
Maxim Dounin 6155ea68a3 SSL: always renewing tickets with TLSv1.3 (ticket #1892).
Chrome only uses TLS session tickets once with TLS 1.3, likely following
RFC 8446 Appendix C.4 recommendation.  With OpenSSL, this works fine with
built-in session tickets, since these are explicitly renewed in case of
TLS 1.3 on each session reuse, but results in only two connections being
reused after an initial handshake when using ssl_session_ticket_key.

Fix is to always renew TLS session tickets in case of TLS 1.3 when using
ssl_session_ticket_key, similarly to how it is done by OpenSSL internally.
2022-01-24 17:18:50 +03:00
Roman Arutyunyan 930ff068d4 QUIC: changed debug message. 2022-01-21 11:20:18 +03:00
Sergey Kandaurov 99d696f0da Merged with the default branch. 2022-01-25 23:42:48 +03:00
Vladimir Homutov d54a5b5884 QUIC: fixed macro style. 2022-01-25 15:48:05 +03:00
Roman Arutyunyan 14a87fa1fa QUIC: fixed chain returned from ngx_quic_write_chain().
Previously, when input ended on a QUIC buffer boundary, input chain was not
advanced to the next buffer.  As a result, ngx_quic_write_chain() returned
a chain with an empty buffer instead of NULL.  This broke HTTP write filter,
preventing it from closing the HTTP request and eventually timing out.

Now input chain is always advanced to a buffer that has data, before checking
QUIC buffer boundary condition.
2022-01-25 09:45:50 +03:00
Vladimir Homutov 4e07aec877 QUIC: removed stale declaration.
The ngx_quic_get_unconnected_socket() was removed in 1e2f4e9c8195.
2022-01-21 11:41:39 +03:00
Vladimir Homutov 31d0317338 QUIC: avoid logging error in case of version negotiation.
Previously, "early error" message was logged in this case.
2022-01-23 21:29:36 +03:00
Vladimir Homutov 9ff3d71a97 QUIC: additional limit for probing packets.
RFC 9000, 9.3.  Responding to Connection Migration:
    An endpoint only changes the address to which it sends packets in
    response to the highest-numbered non-probing packet.

The patch extends this requirement to probing packets.  Although it may
seem excessive, it helps with mitigation of reply attacks (when an off-path
attacker has copied packet with PATH_CHALLENGE and uses different
addresses to exhaust available connection ids).
2022-01-20 22:00:25 +03:00
Pavel Pautov 33b193d870 Core: simplify reader lock release. 2022-01-19 17:37:34 -08:00
Vladimir Homutov 006a271f72 QUIC: reworked migration handling.
The quic connection now holds active, backup and probe paths instead
of sockets.  The number of migration paths is now limited and cannot
be inflated by a bad client or an attacker.

The client id is now associated with path rather than socket. This allows
to simplify processing of output and connection ids handling.

New migration abandons any previously started migrations.  This allows to
free consumed client ids and request new for use in future migrations and
make progress in case when connection id limit is hit during migration.

A path now can be revalidated without losing its state.

The patch also fixes various issues with NAT rebinding case handling:
    - paths are now validated (previously, there was no validation
      and paths were left in limited state)
    - attempt to reuse id on different path is now again verified
      (this was broken in 40445fc7c403)
    - former path is now validated in case of apparent migration
2022-01-19 22:39:24 +03:00
Vladimir Homutov 339eb9ad8b QUIC: the "quic_active_connection_id_limit" directive.
The directive sets corresponding transport parameter and limits number of
created client ids.
2022-01-18 12:49:55 +03:00
Sergey Kandaurov bf0bcce6b4 SSL: free pkey on SSL_CTX_set0_tmp_dh_pkey() failure.
The behaviour was changed in OpenSSL 3.0.1:
https://git.openssl.org/?p=openssl.git;a=commitdiff;h=bf17b7b
2022-01-17 17:05:12 +03:00
Roman Arutyunyan bad85f3f8d QUIC: introduced function ngx_quic_split_chain().
The function splits a buffer at given offset.  The function is now
called from ngx_quic_read_chain() and ngx_quic_write_chain(), which
simplifies both functions.
2022-01-17 14:39:04 +03:00
Roman Arutyunyan bb98e475b6 QUIC: fixed format specifier after 3789f4a56d65. 2022-01-16 00:28:13 +03:00
Roman Arutyunyan 7e2e280495 QUIC: return written size from ngx_quic_write_chain().
This allows to escape calculating it before calling the function.
2022-01-13 11:34:42 +03:00
Sergey Kandaurov 5a825889b6 QUIC: removed ngx_send_lowat() check for QUIC connections.
After 9ae239d2547d, ngx_quic_handle_write_event() no longer runs into
ngx_send_lowat() for QUIC connections, so the check became excessive.
It is assumed that external modules operating with SO_SNDLOWAT
(I'm not aware of any) should do this check on their own.
2022-01-13 15:57:21 +03:00
Sergey Kandaurov ee55da0516 HTTP/3: removed useless warning regarding OpenSSL library.
After 0e6528551f26, it became impossible to run into this path.
2022-01-13 15:57:15 +03:00
Roman Arutyunyan 63a5f45fe4 QUIC: fixed handling stream input buffers.
Previously, ngx_quic_write_chain() treated each input buffer as a memory
buffer, which is not always the case.  Special buffers were not skipped, which
is especially important when hitting the input byte limit.

The issue manifested itself with ngx_quic_write_chain() returning a non-empty
chain consisting of a special last_buf buffer when called from QUIC stream
send_chain().  In order for this to happen, input byte limit should be equal to
the chain length, and the input chain should end with an empty last_buf buffer.
An easy way to achieve this is the following:

  location /empty {
      return 200;
  }

When this non-empty chain was returned from send_chain(), it signalled to the
caller that input was blocked, while in fact it wasn't.  This prevented HTTP
request from finalization, which prevented QUIC from sending STREAM FIN to
the client.  The QUIC stream was then reset after a timeout.

Now special buffers are skipped and send_chain() returns NULL in the case
above, which signals to the caller a successful operation.

Also, original byte limit is now passed to ngx_quic_write_chain() from
send_chain() instead of actual chain length to make sure it's never zero.
2022-01-13 11:23:53 +03:00
Roman Arutyunyan 67e147aacc QUIC: fixed handling STREAM FIN.
Previously, when a STREAM FIN frame with no data bytes was received after all
prior stream data were already read by the application layer, the frame was
ignored and eof was not reported to the application.
2022-01-11 18:57:02 +03:00
Roman Arutyunyan f3327857af HTTP/3: set c->error on read error in ngx_http_test_reading().
Similar to other error/eof cases.
2022-01-12 11:57:46 +03:00
Roman Arutyunyan 8b88be5ed0 HTTP/3: simplified code. 2022-01-12 11:57:06 +03:00
Roman Arutyunyan 668f43ca38 QUIC: modified HTTP version test.
The new condition produces smaller diff to the default branch and is similar to
HTTP/2 case.
2022-01-12 11:54:39 +03:00
Maxim Dounin f59d1b6b12 Avoid sending "Connection: keep-alive" when shutting down.
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.
2022-01-11 02:23:49 +03:00
Sergey Kandaurov d98314233f HTTP/3: improved processing of multiple Cookie field lines.
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-30 12:59:32 +03:00
Maxim Dounin d29c0a2728 Events: fixed balancing between workers with EPOLLEXCLUSIVE.
Linux with EPOLLEXCLUSIVE usually notifies only the process which was first
to add the listening socket to the epoll instance.  As a result most of the
connections are handled by the first worker process (ticket #2285).  To fix
this, we re-add the socket periodically, so other workers will get a chance
to accept connections.
2021-12-30 01:08:46 +03:00
Maxim Dounin 7d591be08f Version bump. 2021-12-29 22:59:53 +03:00
Roman Arutyunyan 22eb20ae31 Style. 2021-12-29 15:33:51 +03:00
Sergey Kandaurov 217bec97be Merged with the default branch. 2021-12-29 15:17:26 +03:00
Maxim Dounin ba9d2fd6cb Support for sendfile(SF_NOCACHE).
The SF_NOCACHE flag, introduced in FreeBSD 11 along with the new non-blocking
sendfile() implementation by glebius@, makes it possible to use sendfile()
along with the "directio" directive.
2021-12-27 19:49:26 +03:00
Maxim Dounin 6b569722a3 SSL: SSL_sendfile(SF_NODISKIO) support. 2021-12-27 19:48:42 +03:00
Maxim Dounin 2d022c44e5 Simplified sendfile(SF_NODISKIO) usage.
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-27 19:48:33 +03:00