summaryrefslogtreecommitdiffhomepage
path: root/src/core (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2024-08-20Version bump.Sergey Kandaurov1-2/+2
2024-08-09Version bump.Sergey Kandaurov1-2/+2
2024-05-23Optimized chain link usage (ticket #2614).Roman Arutyunyan1-2/+8
Previously chain links could sometimes be dropped instead of being reused, which could result in increased memory consumption during long requests. A similar chain link issue in ngx_http_gzip_filter_module was fixed in da46bfc484ef (1.11.10). Based on a patch by Sangmin Lee.
2024-05-03Version bump.Sergey Kandaurov1-2/+2
2024-03-18Fixed undefined behaviour with IPv4-mapped IPv6 addresses.Sergey Kandaurov1-1/+1
Previously, it could result when left-shifting signed integer due to implicit integer promotion, such that the most significant bit appeared on the sign bit. In practice, though, this results in the same left value as with an explicit cast, at least on known compilers, such as GCC and Clang. The reason is that in_addr_t, which is equivalent to uint32_t and same as "unsigned int" in ILP32 and LP64 data type models, has the same type width as the intermediate after integer promotion, so there's no side effects such as sign-extension. This explains why adding an explicit cast does not change object files in practice. Found with UndefinedBehaviorSanitizer (shift). Based on a patch by Piotr Sikora.
2024-03-21Version bump.Roman Arutyunyan1-2/+2
2023-10-27Version bump.Sergey Kandaurov1-2/+2
2023-10-18Core: changed ngx_queue_sort() to use merge sort.Maxim Dounin2-13/+42
This improves nginx startup times significantly when using very large number of locations due to computational complexity of the sorting algorithm being used: insertion sort is O(n*n) on average, while merge sort is O(n*log(n)). In particular, in a test configuration with 20k locations total startup time is reduced from 8 seconds to 0.9 seconds. Prodded by Yusuke Nojima, https://mailman.nginx.org/pipermail/nginx-devel/2023-September/NUL3Y2FPPFSHMPTFTL65KXSXNTX3NQMK.html
2023-10-17Core: fixed memory leak on configuration reload with PCRE2.Maxim Dounin1-3/+4
In ngx_regex_cleanup() allocator wasn't configured when calling pcre2_compile_context_free() and pcre2_match_data_free(), resulting in no ngx_free() call and leaked memory. Fix is ensure that allocator is configured for global allocations, so that ngx_free() is actually called to free memory. Additionally, ngx_regex_compile_context was cleared in ngx_regex_module_init(). It should be either not cleared, so it will be freed by ngx_regex_cleanup(), or properly freed. Fix is to not clear it, so ngx_regex_cleanup() will be able to free it. Reported by ZhenZhong Wu, https://mailman.nginx.org/pipermail/nginx-devel/2023-September/3Z5FIKUDRN2WBSL3JWTZJ7SXDA6YIWPB.html
2023-09-13Modules compatibility: added QUIC to signature (ticket #2539).Roman Arutyunyan1-0/+5
Enabling QUIC changes ngx_connection_t layout, which is why it should be added to the signature.
2023-08-25Version bump.Sergey Kandaurov1-2/+2
2023-08-14QUIC: path MTU discovery.Roman Arutyunyan2-1/+7
MTU selection starts by doubling the initial MTU until the first failure. Then binary search is used to find the path MTU.
2023-07-19Core: fixed environment variables on exit.Maxim Dounin1-2/+51
Similarly to 6822:c045b4926b2c, environment variables introduced with the "env" directive (and "NGINX_BPF_MAPS" added by QUIC) are now allocated via ngx_alloc(), and explicitly freed by a cleanup handler if no longer used. In collaboration with Sergey Kandaurov.
2023-06-20Version bump.Roman Arutyunyan1-2/+2
2023-05-29Version bump.Roman Arutyunyan1-2/+2
2023-05-14Common tree insert function for QUIC and UDP connections.Roman Arutyunyan1-0/+4
Previously, ngx_udp_rbtree_insert_value() was used for plain UDP and ngx_quic_rbtree_insert_value() was used for QUIC. Because of this it was impossible to initialize connection tree in ngx_create_listening() since this function is not aware what kind of listening it creates. Now ngx_udp_rbtree_insert_value() is used for both QUIC and UDP. To make is possible, a generic key field is added to ngx_udp_connection_t. It keeps client address for UDP and connection ID for QUIC.
2023-05-06QUIC: disabled datagram fragmentation.Roman Arutyunyan1-0/+72
As per RFC 9000, Section 14: UDP datagrams MUST NOT be fragmented at the IP layer.
2023-04-18Fixed segfault if regex studies list allocation fails.Maxim Dounin1-3/+3
The rcf->studies list is unconditionally accessed by ngx_regex_cleanup(), and this used to cause NULL pointer dereference if allocation failed. Fix is to set cleanup handler only when allocation succeeds.
2023-04-17Version bump.Sergey Kandaurov1-2/+2
2023-03-10Syslog: introduced error log handler.Maxim Dounin2-9/+41
This ensures that errors which happen during logging to syslog are logged with proper context, such as "while logging to syslog" and the server name. Prodded by Safar Safarly.
2023-03-10Syslog: removed usage of ngx_cycle->log and ngx_cycle->hostname.Maxim Dounin2-18/+24
During initial startup the ngx_cycle->hostname is not available, and previously this resulted in incorrect logging. Instead, hostname from the configuration being parsed is now preserved in the syslog peer structure and then used during logging. Similarly, ngx_cycle->log might not match the configuration where the syslog peer is defined if the configuration is not yet fully applied, and previously this resulted in unexpected logging of syslog errors and debug information. Instead, cf->cycle->new_log is now referenced in the syslog peer structure and used for logging, similarly to how it is done in other modules.
2023-02-23Core: stricter UTF-8 handling in ngx_utf8_decode().Yugo Horie1-1/+6
An UTF-8 octet sequence cannot start with a 11111xxx byte (above 0xf8), see https://datatracker.ietf.org/doc/html/rfc3629#section-3. Previously, such bytes were accepted by ngx_utf8_decode() and misinterpreted as 11110xxx bytes (as in a 4-byte sequence). While unlikely, this can potentially cause issues. Fix is to explicitly reject such bytes in ngx_utf8_decode().
2023-02-02Lingering close for connections with pipelined requests.Maxim Dounin1-0/+1
This is expected to help with clients using pipelining with some constant depth, such as apt[1][2]. When downloading many resources, apt uses pipelining with some constant depth, a number of requests in flight. This essentially means that after receiving a response it sends an additional request to the server, and this can result in requests arriving to the server at any time. Further, additional requests are sent one-by-one, and can be easily seen as such (neither as pipelined, nor followed by pipelined requests). The only safe approach to close such connections (for example, when keepalive_requests is reached) is with lingering. To do so, now nginx monitors if pipelining was used on the connection, and if it was, closes the connection with lingering. [1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=973861#10 [2] https://mailman.nginx.org/pipermail/nginx-devel/2023-January/ZA2SP5SJU55LHEBCJMFDB2AZVELRLTHI.html
2022-12-21Updated link to OpenVZ suspend/resume bug.Maxim Dounin1-1/+1
2022-12-16Style.BullerDu1-2/+2
2022-12-16Version bump.Sergey Kandaurov1-2/+2
2022-11-30Removed casts from ngx_memcmp() macro.Maxim Dounin1-1/+1
Casts are believed to be not needed, since memcmp() has "const void *" arguments since introduction of the "void" type in C89. And on pre-C89 platforms nginx is unlikely to compile without warnings anyway, as there are no casts in memcpy() and memmove() calls. These casts were added in 1648:89a47f19b9ec without any details on why they were added, and Igor does not remember details either. The most plausible explanation is that they were copied from ngx_strcmp() and were not really needed even at that time. Prodded by Alejandro Colomar.
2022-11-30Fixed alignment of ngx_memmove()/ngx_movemem() macro definitions.Maxim Dounin1-2/+2
2022-11-08Fixed PROXY protocol to use ngx_memcpy()/ngx_memcmp().Maxim Dounin1-5/+5
2022-11-08Added logging to PROXY protocol write buffer check.Maxim Dounin1-0/+2
The check is not expected to fail unless there is a bug in the calling code. But given the check is here, it should log an alert if it fails instead of silently closing the connection.
2022-11-02Increased maximum read PROXY protocol header size.Roman Arutyunyan2-2/+3
Maximum size for reading the PROXY protocol header is increased to 4096 to accommodate a bigger number of TLVs, which are supported since cca4c8a715de. Maximum size for writing the PROXY protocol header is not changed since only version 1 is currently supported.
2022-11-03Version bump.Roman Arutyunyan1-2/+2
2022-09-27Added type cast to ngx_proxy_protocol_parse_uint16().Roman Arutyunyan1-1/+3
The cast is added to make ngx_proxy_protocol_parse_uint16() similar to ngx_proxy_protocol_parse_uint32().
2022-10-12PROXY protocol v2 TLV variables.Roman Arutyunyan2-2/+187
The variables have prefix $proxy_protocol_tlv_ and are accessible by name and by type. Examples are: $proxy_protocol_tlv_0x01, $proxy_protocol_tlv_alpn.
2022-10-10Log only the first line of user input on PROXY protocol v1 error.Roman Arutyunyan1-1/+7
Previously, all received user input was logged. If a multi-line text was received from client and logged, it could reduce log readability and also make it harder to parse nginx log by scripts. The change brings to PROXY protocol the same behavior that exists for HTTP request line in ngx_http_log_error_handler().
2022-08-30Version bump.Maxim Dounin1-2/+2
2022-07-14Resolver: fixed memory leak for the "ipv4=off" case.Sergey Kandaurov1-4/+1
This change partially reverts 2a77754cd9fe to properly free rn->query. Found by Coverity (CID 1507244).
2022-07-12The "ipv4=" parameter of the "resolver" directive.Ruslan Ermilov2-15/+54
When set to "off", only IPv6 addresses will be resolved, and no A queries are ever sent (ticket #2196).
2022-06-29Version bump.Maxim Dounin1-2/+2
2022-06-01Resolver: make TCP write timer event cancelable.Aleksei Bavshin1-0/+1
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-05-30FastCGI: combining headers with identical names (ticket #1724).Maxim Dounin1-2/+5
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-30Version bump.Maxim Dounin1-2/+2
2022-04-20QUIC: separate UDP framework for QUIC.Roman Arutyunyan1-4/+0
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-02-03HTTP/2: made it possible to flush response headers (ticket #1743).Maxim Dounin1-0/+1
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-01-27Version bump.Vladimir Homutov1-2/+2
2022-01-19Core: simplify reader lock release.Pavel Pautov1-15/+3
2021-12-29Version bump.Maxim Dounin1-2/+2
2021-12-27Support for sendfile(SF_NOCACHE).Maxim Dounin1-4/+13
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-27Simplified sendfile(SF_NODISKIO) usage.Maxim Dounin4-37/+2
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-25Core: added NGX_REGEX_MULTILINE for 3rd party modules.Maxim Dounin2-2/+11
Notably, NAXSI is known to misuse ngx_regex_compile() with rc.options set to PCRE_CASELESS | PCRE_MULTILINE. With PCRE2 support, and notably binary compatibility changes, it is no longer possible to set PCRE[2]_MULTILINE option without using proper interface. To facilitate correct usage, this change adds the NGX_REGEX_MULTILINE option.