Welcome! Log In Create A New Profile

Advanced

[nginx] Core: disabled SO_REUSEADDR on UDP sockets while testing config.

Maxim Dounin
May 31, 2021 10:40AM
details: https://hg.nginx.org/nginx/rev/46815874bcc6
branches:
changeset: 7868:46815874bcc6
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon May 31 16:36:51 2021 +0300
description:
Core: disabled SO_REUSEADDR on UDP sockets while testing config.

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.

diffstat:

src/core/ngx_connection.c | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)

diffs (39 lines):

diff -r c860f0b7010c -r 46815874bcc6 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Mon May 31 16:36:37 2021 +0300
+++ b/src/core/ngx_connection.c Mon May 31 16:36:51 2021 +0300
@@ -495,21 +495,24 @@ ngx_open_listening_sockets(ngx_cycle_t *
return NGX_ERROR;
}

- if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
- (const void *) &reuseaddr, sizeof(int))
- == -1)
- {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "setsockopt(SO_REUSEADDR) %V failed",
- &ls[i].addr_text);
+ if (ls[i].type != SOCK_DGRAM || !ngx_test_config) {

- if (ngx_close_socket(s) == -1) {
+ if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
+ (const void *) &reuseaddr, sizeof(int))
+ == -1)
+ {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_close_socket_n " %V failed",
+ "setsockopt(SO_REUSEADDR) %V failed",
&ls[i].addr_text);
- }

- return NGX_ERROR;
+ if (ngx_close_socket(s) == -1) {
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
+ ngx_close_socket_n " %V failed",
+ &ls[i].addr_text);
+ }
+
+ return NGX_ERROR;
+ }
}

#if (NGX_HAVE_REUSEPORT)
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Core: disabled SO_REUSEADDR on UDP sockets while testing config.

Maxim Dounin 136 May 31, 2021 10:40AM



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

Online Users

Guests: 63
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready