aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_connection.c
Commit message (Collapse)AuthorAge
* Core: added support for TCP keepalive parameters on macOS.Sergey Kandaurov2025-05-27
| | | | | | | | | | | | | | | | The support first appeared in OS X Mavericks 10.9 and documented since OS X Yosemite 10.10. It has a subtle implementation difference from other operating systems in that the TCP_KEEPALIVE socket option (used in place of TCP_KEEPIDLE) isn't inherited from a listening socket to an accepted socket. An apparent reason for this behaviour is that it might be preserved for the sake of backward compatibility. The TCP_KEEPALIVE socket option is not inherited since appearance in OS X Panther 10.3, which long predates two other TCP_KEEPINTVL and TCP_KEEPCNT socket options. Thanks to Andy Pan for initial work.
* QUIC: path MTU discovery.Roman Arutyunyan2023-08-14
| | | | | MTU selection starts by doubling the initial MTU until the first failure. Then binary search is used to find the path MTU.
* Common tree insert function for QUIC and UDP connections.Roman Arutyunyan2023-05-14
| | | | | | | | | | | 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.
* QUIC: disabled datagram fragmentation.Roman Arutyunyan2023-05-06
| | | | | | As per RFC 9000, Section 14: UDP datagrams MUST NOT be fragmented at the IP layer.
* Merged with the default branch.Sergey Kandaurov2023-01-02
|\
| * Updated link to OpenVZ suspend/resume bug.Maxim Dounin2022-12-21
| |
* | QUIC: separate UDP framework for QUIC.Roman Arutyunyan2022-04-20
| | | | | | | | | | | | | | 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.
* | QUIC: store QUIC connection fd in stream fake connection.Roman Arutyunyan2021-09-06
| | | | | | | | | | | | Previously it had -1 as fd. This fixes proxying, which relies on downstream connection having a real fd. Also, this reduces diff to the default branch for ngx_close_connection().
* | Merged with the default branch.Sergey Kandaurov2021-07-15
|\|
| * Core: disabled SO_REUSEADDR on UDP sockets while testing config.Maxim Dounin2021-05-31
| | | | | | | | | | | | | | | | | | | | | | On Linux, SO_REUSEADDR allows completely duplicate UDP sockets, so using SO_REUSEADDR when testing configuration results in packets being dropped if there is an existing traffic on the sockets being tested (ticket #2187). While dropped packets are expected with UDP, it is better to avoid this when possible. With this change, SO_REUSEADDR is no longer set on datagram sockets when testing configuration.
* | Merged with the default branch.Sergey Kandaurov2021-02-17
|\|
| * Additional connections reuse.Maxim Dounin2021-02-11
| | | | | | | | | | | | | | | | | | If ngx_drain_connections() fails to immediately reuse any connections and there are no free connections, it now additionally tries to reuse a connection again. This helps to provide at least one free connection in case of HTTP/2 with lingering close, where merely trying to reuse a connection once does not free it, but makes it reusable again, waiting for lingering close.
* | Merged with the default branch.Roman Arutyunyan2020-08-18
|\|
| * Core: reusing connections in advance.Maxim Dounin2020-08-10
| | | | | | | | | | | | | | | | | | | | | | | | | | Reworked connections reuse, so closing connections is attempted in advance, as long as number of free connections is less than 1/16 of worker connections configured. This ensures that new connections can be handled even if closing a reusable connection requires some time, for example, for a lingering close (ticket #2017). The 1/16 ratio is selected to be smaller than 1/8 used for disabling accept when working with accept mutex, so nginx will try to balance new connections to different workers first, and will start reusing connections only if this won't help.
| * Core: added a warning about reusing connections.Maxim Dounin2020-08-10
| | | | | | | | | | | | | | | | | | | | | | Previously, reusing connections happened silently and was only visible in monitoring systems. This was shown to be not very user-friendly, and administrators often didn't realize there were too few connections available to withstand the load, and configured timeouts (keepalive_timeout and http2_idle_timeout) were effectively reduced to keep things running. To provide at least some information about this, a warning is now logged (at most once per second, to avoid flooding the logs).
* | QUIC: added "quic" listen parameter.Roman Arutyunyan2020-07-21
| | | | | | | | | | | | The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there
* | Merged with the default branch.Sergey Kandaurov2020-07-13
|\|
| * Fixed removing of listening UNIX sockets when "changing binary".Ruslan Ermilov2020-06-01
| | | | | | | | | | | | When changing binary, sending a SIGTERM to the new binary's master process should not remove inherited UNIX sockets unless the old binary's master process has exited.
* | Do not close QUIC sockets in ngx_close_listening_sockets().Sergey Kandaurov2020-06-23
| | | | | | | | This breaks graceful shutdown of QUIC connections in terms of quic-transport.
* | Fixed sanitizer errors.Roman Arutyunyan2020-03-13
|/
* Events: moved sockets cloning to ngx_event_init_conf().Maxim Dounin2018-07-12
| | | | | | | | | Previously, listenings sockets were not cloned if the worker_processes directive was specified after "listen ... reuseport". This also simplifies upcoming configuration check on the number of worker connections, as it needs to know the number of listening sockets before cloning.
* Added FreeBSD support for "listen ... reuseport".Ruslan Ermilov2018-07-02
|
* Stream: udp streams.Roman Arutyunyan2018-06-04
| | | | | | | | | | | | | | | | | Previously, only one client packet could be processed in a udp stream session even though multiple response packets were supported. Now multiple packets coming from the same client address and port are delivered to the same stream session. If it's required to maintain a single stream of data, nginx should be configured in a way that all packets from a client are delivered to the same worker. On Linux and DragonFly BSD the "reuseport" parameter should be specified for this. Other systems do not currently provide appropriate mechanisms. For these systems a single stream of udp packets is only guaranteed in single-worker configurations. The proxy_response directive now specifies how many packets are expected in response to a single client packet.
* Core: silenced getsockopt(TCP_FASTOPEN) messages on FreeBSD.Maxim Dounin2018-05-21
| | | | | | | FreeBSD returns EINVAL when getsockopt(TCP_FASTOPEN) is called on a unix domain socket, resulting in "getsockopt(TCP_FASTOPEN) ... failed" messages during binary upgrade when unix domain listen sockets are present in the configuration. Added EINVAL to the list of ignored error codes.
* Fixed buffer overread with unix sockets after accept().Maxim Dounin2017-10-04
| | | | | | | | | | | | | | | | | Some OSes (notably macOS, NetBSD, and Solaris) allow unix socket addresses larger than struct sockaddr_un. Moreover, some of them (macOS, Solaris) return socklen of the socket address before it was truncated to fit the buffer provided. As such, on these systems socklen must not be used without additional check that it is within the buffer provided. Appropriate checks added to ngx_event_accept() (after accept()), ngx_event_recvmsg() (after recvmsg()), and ngx_set_inherited_sockets() (after getsockname()). We also obtain socket addresses via getsockname() in ngx_connection_local_sockaddr(), but it does not need any checks as it is only used for INET and INET6 sockets (as there can be no wildcard unix sockets).
* Core: fixed error message on setsockopt(SO_REUSEPORT) failure.Maxim Dounin2017-07-11
| | | | | The error is fatal when configuring a new socket, so the ", ignored" part is not appropriate and was removed.
* Core: disabled SO_REUSEPORT when testing config (ticket #1300).Maxim Dounin2017-07-11
| | | | | | | | | | | | | | | | | | When closing a socket with SO_REUSEPORT, Linux drops all connections waiting in this socket's listen queue. Previously, it was believed to only result in connection resets when reconfiguring nginx to use smaller number of worker processes. It also results in connection resets during configuration testing though. Workaround is to avoid using SO_REUSEPORT when testing configuration. It should prevent listening sockets from being created if a conflicting socket already exists, while still preserving detection of other possible errors. It should also cover UDP sockets. The only downside of this approach seems to be that a configuration testing won't be able to properly report the case when nginx was compiled with SO_REUSEPORT, but the kernel is not able to set it. Such errors will be reported on a real start instead.
* Introduced ngx_tcp_nodelay().Ruslan Ermilov2017-05-26
|
* Improved connection draining with small number of connections.Maxim Dounin2017-01-20
| | | | | | | | | | | | Closing up to 32 connections might be too aggressive if worker_connections is set to a comparable number (and/or there are only a small number of reusable connections). If an occasional connection shorage happens in such a configuration, it leads to closing all reusable connections instead of gradually reducing keepalive timeout to a smaller value. To improve granularity in such configurations we now close no more than 1/8 of all reusable connections at once. Suggested by Joel Cunningham.
* Added cycle parameter to ngx_drain_connections().Maxim Dounin2017-01-20
| | | | No functional changes, mostly style.
* Core: use c->log while closing connection.Ruslan Ermilov2016-10-05
| | | | c->pool is not destroyed here since c52408583801.
* Introduced the ngx_sockaddr_t type.Ruslan Ermilov2016-05-23
| | | | It's properly aligned and can hold any supported sockaddr.
* Belatedly changed the ngx_create_listening() prototype.Ruslan Ermilov2016-05-20
| | | | The function is called only with "struct sockaddr *" since 0.7.58.
* Style.Ruslan Ermilov2016-03-30
|
* Fixed socket inheritance on reload and binary upgrade.Roman Arutyunyan2016-03-25
| | | | | | | | | | On nginx reload or binary upgrade, an attempt is made to inherit listen sockets from the previous configuration. Previously, no check for socket type was made and the inherited socket could have the wrong type. On binary upgrade, socket type was not detected at all. Wrong socket type could lead to errors on that socket due to different logic and unsupported syscalls. For example, a UDP socket, inherited as TCP, lead to the following error after arrival of a datagram: "accept() failed (102: Operation not supported on socket)".
* Stream: UDP proxy.Roman Arutyunyan2016-01-20
|
* Win32: fixed build with MinGW and MinGW-w64 gcc.Kouhei Sutou2015-10-17
| | | | | This change fixes the "comparison between signed and unsigned integer expressions" warning, introduced in 5e6142609e48 (1.9.4).
* Core: idle connections now closed only once on exiting.Valentin Bartenev2015-08-11
| | | | | | | | | | | | Iterating through all connections takes a lot of CPU time, especially with large number of worker connections configured. As a result nginx processes used to consume CPU time during graceful shutdown. To mitigate this we now only do a full scan for idle connections when shutdown signal is received. Transitions of connections to idle ones are now expected to be avoided if the ngx_exiting flag is set. The upstream keepalive module was modified to follow this.
* Workaround for "configuration file test failed" under OpenVZ.Gena Makhomed2015-07-23
| | | | | | | | | | | | | | | | | | | | | | If nginx was used under OpenVZ and a container with nginx was suspended and resumed, configuration tests started to fail because of EADDRINUSE returned from listen() instead of bind(): # nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use) nginx: configuration file /etc/nginx/nginx.conf test failed With this change EADDRINUSE errors returned by listen() are handled similarly to errors returned by bind(), and configuration tests work fine in the same environment: # nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful More details about OpenVZ suspend/resume bug: https://bugzilla.openvz.org/show_bug.cgi?id=2470
* The "reuseport" option of the "listen" directive.Maxim Dounin2015-05-20
| | | | | | | | | | | | | | | When configured, an individual listen socket on a given address is created for each worker process. This allows to reduce in-kernel lock contention on configurations with high accept rates, resulting in better performance. As of now it works on Linux and DragonFly BSD. Note that on Linux incoming connection requests are currently tied up to a specific listen socket, and if some sockets are closed, connection requests will be reset, see https://lwn.net/Articles/542629/. With nginx, this may happen if the number of worker processes is reduced. There is no such problem on DragonFly BSD. Based on previous work by Sepherosa Ziehau and Yingqi Lu.
* Removed the obsolete rtsig module.Ruslan Ermilov2015-04-23
|
* Removed the obsolete aio module.Ruslan Ermilov2015-04-22
|
* Removed stub implementation of win32 mutexes.Ruslan Ermilov2015-03-23
|
* Removed ngx_connection_t.lock.Ruslan Ermilov2015-03-20
|
* Renamed NGX_THREADS to NGX_OLD_THREADS because of deprecation.Ruslan Ermilov2015-03-04
| | | | It's mostly dead code and the original idea of worker threads has been rejected.
* Core: make ngx_connection_local_sockaddr() always assign address.Roman Arutyunyan2015-02-17
| | | | | | Previously, this function checked for connection local address existence and returned error if it was missing. Now a new address is assigned in this case making it possible to call this function not only for accepted connections.
* Events: processing of posted events changed from LIFO to FIFO.Valentin Bartenev2014-09-01
| | | | | | | In theory, this can provide a bit better distribution of latencies. Also it simplifies the code, since ngx_queue_t is now used instead of custom implementation.
* Events: removed broken thread support from posted events.Valentin Bartenev2014-09-01
| | | | | It's mostly dead code. And the idea of thread support for this task has been deprecated.
* Core: plugged socket leak during configuration test.Maxim Dounin2014-06-26
| | | | | | | | This isn't really important as configuration testing shortly ends with a process termination which will free all sockets, though Coverity complains. Prodded by Coverity (CID 400872).
* Core: allocate enough memory to hold IPv6 text address plus port.Ruslan Ermilov2014-02-22
|