summaryrefslogtreecommitdiffhomepage
path: root/src/core/ngx_connection.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
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>
2014-01-30Core: handle getsockopt(TCP_FASTOPEN) failures.Piotr Sikora1-4/+8
Linux returns EOPNOTSUPP for non-TCP sockets and ENOPROTOOPT for TCP sockets, because getsockopt(TCP_FASTOPEN) is not implemented so far. While there, lower the log level from ALERT to NOTICE to match other getsockopt() failures. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2014-01-28Fixed TCP_DEFER_ACCEPT handling (ticket #353).Maxim Dounin1-1/+7
Backed out 05a56ebb084a, as it turns out that kernel can return connections without any delay if syncookies are used. This basically means we can't assume anything about connections returned with deferred accept set. To solve original problem the 05a56ebb084a tried to solve, i.e. to don't wait longer than needed if a connection was accepted after deferred accept timeout, this patch changes a timeout set with setsockopt(TCP_DEFER_ACCEPT) to 1 second, unconditionally. This is believed to be enough for speed improvements, and doesn't imply major changes to timeouts used. Note that before 2.6.32 connections were dropped after a timeout. Though it is believed that 1s is still appropriate for kernels before 2.6.32, as previously tcp_synack_retries controlled the actual timeout and 1s results in more than 1 minute actual timeout by default.
2013-12-19Fixed the first argument to getsockopt().Ruslan Ermilov1-2/+6
While here, always initialize the last argument.
2013-12-09Fixed handling of UNIX-domain sockets.Ruslan Ermilov1-0/+6
When evaluating $local_port, $server_port, and $server_addr, UNIX-domain sockets were mistakenly interpreted as IPv4 sockets.
2013-12-09Core: keep the length of the local sockaddr.Ruslan Ermilov1-3/+8
2013-12-03Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.Mathew Rodley1-0/+32
--- auto/unix | 12 ++++++++++++ src/core/ngx_connection.c | 32 ++++++++++++++++++++++++++++++++ src/core/ngx_connection.h | 4 ++++ src/http/ngx_http.c | 4 ++++ src/http/ngx_http_core_module.c | 21 +++++++++++++++++++++ src/http/ngx_http_core_module.h | 3 +++ 6 files changed, 76 insertions(+)
2013-10-31Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.Maxim Dounin1-2/+10
Recent Linux versions started to return EOPNOTSUPP to getsockopt() calls on unix sockets, resulting in log pollution on binary upgrade. Such errors are silently ignored now.
2013-09-04Win32: MinGW GCC compatibility.Maxim Dounin1-3/+3
Several warnings silenced, notably (ngx_socket_t) -1 is now checked on socket operations instead of -1, as ngx_socket_t is unsigned on win32 and gcc complains on comparison. With this patch, it's now possible to compile nginx using mingw gcc, with options we normally compile on win32.
2013-07-25On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.Ruslan Ermilov1-4/+16
Based on a patch by Sepherosa Ziehau.
2013-07-25Style: reuse one int variable in ngx_configure_listening_sockets().Ruslan Ermilov1-11/+8
No functional changes.
2013-07-11Core: fixed possible use of an uninitialized variable.Vladimir Homutov1-0/+2
The call to ngx_sock_ntop() in ngx_connection_local_sockaddr() might be performed with the uninitialized "len" variable. The fix is to initialize variable to the size of corresponding socket address type. The issue was introduced in commit 05ba5bce31e0.
2013-07-11Core: extended ngx_sock_ntop() with socklen parameter.Vladimir Homutov1-3/+4
On Linux, sockaddr length is required to process unix socket addresses properly due to unnamed sockets (which don't have sun_path set at all) and abstract namespace sockets.
2013-03-25Use NGX_FILE_ERROR for handling file operations errors.Valentin Bartenev1-2/+2
On Win32 platforms 0 is used to indicate errors in file operations, so comparing against -1 is not portable. This was not much of an issue in patched code, since only ngx_fd_info() test is actually reachable on Win32 and in worst case it might result in bogus error log entry. Patch by Piotr Sikora.
2013-03-15Status: introduced the "ngx_stat_waiting" counter.Valentin Bartenev1-0/+8
And corresponding variable $connections_waiting was added. Previously, waiting connections were counted as the difference between active connections and the sum of reading and writing connections. That made it impossible to count more than one request in one connection as reading or writing (as is the case for SPDY). Also, we no longer count connections in handshake state as waiting.
2013-03-07Removed c->single_connection flag.Valentin Bartenev1-5/+3
The c->single_connection was intended to be used as lock mechanism to serialize modifications of request object from several threads working with client and upstream connections. The flag is redundant since threads in nginx have never been used that way.
2012-11-20Fixed failure to start cache manager and cache loader processesIgor Sysoev1-0/+2
if there were more than 512 listening sockets in configuration.
2012-07-30Core: ipv6only is now on by default.Ruslan Ermilov1-2/+2
There is a general consensus that this change results in better consistency between different operating systems and differently tuned operating systems. Note: this changes the width and meaning of the ipv6only field of the ngx_listening_t structure. 3rd party modules that create their own listening sockets might need fixing.
2012-04-03Fixed spelling in multiline C comments.Ruslan Ermilov1-1/+1
2012-03-05Whitespace fixes.Maxim Dounin1-1/+1
2012-01-18Copyright updated.Maxim Konovalov1-0/+1
2011-12-05Added the "so_keepalive=" parameter to the "listen" directive.Valentin Bartenev1-0/+51
The "so_keepalive" directive in mail module was deprecated. Thanks to Vsevolod Stakhov for initial work.
2011-08-21Move SO_ACCEPTFILTER and TCP_DEFER_ACCEPT checks into configure.Maxim Dounin1-1/+1
NetBSD 5.0+ has SO_ACCEPTFILTER support merged from FreeBSD, and having accept filter check in FreeBSD-specific ngx_freebsd_config.h prevents it from being used on NetBSD. Therefore move the check into configure (and do the same for Linux-specific TCP_DEFER_ACCEPT, just to be in line).
2011-04-04reuse keepalive connections if there are no free worker connectionsIgor Sysoev1-0/+55
patch by Maxim Dounin
2010-07-05listen setfib=XIgor Sysoev1-0/+36