summaryrefslogtreecommitdiffhomepage
path: root/src/core/ngx_connection.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2023-08-14QUIC: path MTU discovery.Roman Arutyunyan1-0/+5
MTU selection starts by doubling the initial MTU until the first failure. Then binary search is used to find the path MTU.
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-01-02Merged with the default branch.Sergey Kandaurov1-1/+1
2022-12-21Updated link to OpenVZ suspend/resume bug.Maxim Dounin1-1/+1
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.
2021-09-06QUIC: store QUIC connection fd in stream fake connection.Roman Arutyunyan1-6/+6
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().
2021-07-15Merged with the default branch.Sergey Kandaurov1-11/+14
2021-05-31Core: disabled SO_REUSEADDR on UDP sockets while testing config.Maxim Dounin1-11/+14
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.
2021-02-17Merged with the default branch.Sergey Kandaurov1-0/+16
2021-02-11Additional connections reuse.Maxim Dounin1-0/+16
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.
2020-08-18Merged with the default branch.Roman Arutyunyan1-5/+17
2020-08-10Core: reusing connections in advance.Maxim Dounin1-6/+5
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.
2020-08-10Core: added a warning about reusing connections.Maxim Dounin1-0/+13
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).
2020-07-21QUIC: added "quic" listen parameter.Roman Arutyunyan1-0/+2
The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there
2020-07-13Merged with the default branch.Sergey Kandaurov1-1/+2
2020-06-23Do not close QUIC sockets in ngx_close_listening_sockets().Sergey Kandaurov1-0/+4
This breaks graceful shutdown of QUIC connections in terms of quic-transport.
2020-06-01Fixed removing of listening UNIX sockets when "changing binary".Ruslan Ermilov1-1/+2
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.
2020-03-13Fixed sanitizer errors.Roman Arutyunyan1-6/+6
2018-07-12Events: moved sockets cloning to ngx_event_init_conf().Maxim Dounin1-5/+4
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.
2018-07-02Added FreeBSD support for "listen ... reuseport".Ruslan Ermilov1-0/+54
2018-06-04Stream: udp streams.Roman Arutyunyan1-0/+4
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.
2018-05-21Core: silenced getsockopt(TCP_FASTOPEN) messages on FreeBSD.Maxim Dounin1-1/+3
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.
2017-10-04Fixed buffer overread with unix sockets after accept().Maxim Dounin1-0/+4
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).
2017-07-11Core: fixed error message on setsockopt(SO_REUSEPORT) failure.Maxim Dounin1-1/+1
The error is fatal when configuring a new socket, so the ", ignored" part is not appropriate and was removed.
2017-07-11Core: disabled SO_REUSEPORT when testing config (ticket #1300).Maxim Dounin1-1/+1
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.
2017-05-26Introduced ngx_tcp_nodelay().Ruslan Ermilov1-0/+43
2017-01-20Improved connection draining with small number of connections.Maxim Dounin1-2/+6
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.
2017-01-20Added cycle parameter to ngx_drain_connections().Maxim Dounin1-5/+5
No functional changes, mostly style.
2016-10-05Core: use c->log while closing connection.Ruslan Ermilov1-4/+1
c->pool is not destroyed here since c52408583801.
2016-05-23Introduced the ngx_sockaddr_t type.Ruslan Ermilov1-5/+5
It's properly aligned and can hold any supported sockaddr.
2016-05-20Belatedly changed the ngx_create_listening() prototype.Ruslan Ermilov1-1/+2
The function is called only with "struct sockaddr *" since 0.7.58.
2016-03-30Style.Ruslan Ermilov1-18/+18
2016-03-25Fixed socket inheritance on reload and binary upgrade.Roman Arutyunyan1-0/+16
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)".
2016-01-20Stream: UDP proxy.Roman Arutyunyan1-10/+82
2015-10-17Win32: fixed build with MinGW and MinGW-w64 gcc.Kouhei Sutou1-1/+1
This change fixes the "comparison between signed and unsigned integer expressions" warning, introduced in 5e6142609e48 (1.9.4).
2015-08-11Core: idle connections now closed only once on exiting.Valentin Bartenev1-0/+20
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.
2015-07-23Workaround for "configuration file test failed" under OpenVZ.Gena Makhomed1-4/+22
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
2015-05-20The "reuseport" option of the "listen" directive.Maxim Dounin1-0/+110
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.
2015-04-23Removed the obsolete rtsig module.Ruslan Ermilov1-4/+1
2015-04-22Removed the obsolete aio module.Ruslan Ermilov1-1/+1
2015-03-23Removed stub implementation of win32 mutexes.Ruslan Ermilov1-10/+0
2015-03-20Removed ngx_connection_t.lock.Ruslan Ermilov1-12/+0
2015-03-04Renamed NGX_THREADS to NGX_OLD_THREADS because of deprecation.Ruslan Ermilov1-1/+1
It's mostly dead code and the original idea of worker threads has been rejected.
2015-02-17Core: make ngx_connection_local_sockaddr() always assign address.Roman Arutyunyan1-17/+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.
2014-09-01Events: processing of posted events changed from LIFO to FIFO.Valentin Bartenev1-2/+2
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.
2014-09-01Events: removed broken thread support from posted events.Valentin Bartenev1-20/+1
It's mostly dead code. And the idea of thread support for this task has been deprecated.
2014-06-26Core: plugged socket leak during configuration test.Maxim Dounin1-6/+6
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).
2014-02-22Core: allocate enough memory to hold IPv6 text address plus port.Ruslan Ermilov1-1/+1
2014-02-03Use ngx_socket_errno where appropriate.Piotr Sikora1-5/+5
Signed-off-by: Piotr Sikora <piotr@cloudflare.com>