Mercurial > hg > nginx
comparison src/core/ngx_connection.c @ 7868:46815874bcc6
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 31 May 2021 16:36:51 +0300 |
parents | 6d98f29867e8 |
children | 07b0bee87f32 6674a50cbb6c |
comparison
equal
deleted
inserted
replaced
7867:c860f0b7010c | 7868:46815874bcc6 |
---|---|
493 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, | 493 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
494 ngx_socket_n " %V failed", &ls[i].addr_text); | 494 ngx_socket_n " %V failed", &ls[i].addr_text); |
495 return NGX_ERROR; | 495 return NGX_ERROR; |
496 } | 496 } |
497 | 497 |
498 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, | 498 if (ls[i].type != SOCK_DGRAM || !ngx_test_config) { |
499 (const void *) &reuseaddr, sizeof(int)) | 499 |
500 == -1) | 500 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, |
501 { | 501 (const void *) &reuseaddr, sizeof(int)) |
502 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, | 502 == -1) |
503 "setsockopt(SO_REUSEADDR) %V failed", | 503 { |
504 &ls[i].addr_text); | |
505 | |
506 if (ngx_close_socket(s) == -1) { | |
507 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, | 504 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
508 ngx_close_socket_n " %V failed", | 505 "setsockopt(SO_REUSEADDR) %V failed", |
509 &ls[i].addr_text); | 506 &ls[i].addr_text); |
510 } | 507 |
511 | 508 if (ngx_close_socket(s) == -1) { |
512 return NGX_ERROR; | 509 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
510 ngx_close_socket_n " %V failed", | |
511 &ls[i].addr_text); | |
512 } | |
513 | |
514 return NGX_ERROR; | |
515 } | |
513 } | 516 } |
514 | 517 |
515 #if (NGX_HAVE_REUSEPORT) | 518 #if (NGX_HAVE_REUSEPORT) |
516 | 519 |
517 if (ls[i].reuseport && !ngx_test_config) { | 520 if (ls[i].reuseport && !ngx_test_config) { |