Welcome! Log In Create A New Profile

Advanced

[nginx] Fixed socket inheritance on reload and binary upgrade.

Roman Arutyunyan
March 25, 2016 07:14AM
details: http://hg.nginx.org/nginx/rev/fd4b52e74f96
branches:
changeset: 6462:fd4b52e74f96
user: Roman Arutyunyan <arut@nginx.com>
date: Fri Mar 25 14:10:38 2016 +0300
description:
Fixed socket inheritance on reload and binary upgrade.

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)".

diffstat:

src/core/ngx_connection.c | 16 ++++++++++++++++
src/core/ngx_cycle.c | 4 ++++
2 files changed, 20 insertions(+), 0 deletions(-)

diffs (47 lines):

diff -r a01e315b3a78 -r fd4b52e74f96 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Fri Mar 18 19:53:22 2016 +0300
+++ b/src/core/ngx_connection.c Fri Mar 25 14:10:38 2016 +0300
@@ -210,6 +210,18 @@ ngx_set_inherited_sockets(ngx_cycle_t *c

olen = sizeof(int);

+ if (getsockopt(ls[i].fd, SOL_SOCKET, SO_TYPE, (void *) &ls[i].type,
+ &olen)
+ == -1)
+ {
+ ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_socket_errno,
+ "getsockopt(SO_TYPE) %V failed", &ls[i].addr_text);
+ ls[i].ignore = 1;
+ continue;
+ }
+
+ olen = sizeof(int);
+
if (getsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF, (void *) &ls[i].rcvbuf,
&olen)
== -1)
@@ -274,6 +286,10 @@ ngx_set_inherited_sockets(ngx_cycle_t *c

#endif

+ if (ls[i].type != SOCK_STREAM) {
+ continue;
+ }
+
#if (NGX_HAVE_TCP_FASTOPEN)

olen = sizeof(int);
diff -r a01e315b3a78 -r fd4b52e74f96 src/core/ngx_cycle.c
--- a/src/core/ngx_cycle.c Fri Mar 18 19:53:22 2016 +0300
+++ b/src/core/ngx_cycle.c Fri Mar 25 14:10:38 2016 +0300
@@ -512,6 +512,10 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
continue;
}

+ if (ls[i].type != nls[n].type) {
+ continue;
+ }
+
if (ngx_cmp_sockaddr(nls[n].sockaddr, nls[n].socklen,
ls[i].sockaddr, ls[i].socklen, 1)
== NGX_OK)

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Fixed socket inheritance on reload and binary upgrade.

Roman Arutyunyan 524 March 25, 2016 07:14AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 171
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready