[PATCH] Workaround for "configuration file test failed" under OpenVZ

Gena Makhomed gmm at csdoc.com
Wed Jul 29 22:44:15 UTC 2015


# HG changeset patch
# User Gena Makhomed <gmm at csdoc.com>
# Date 1437674403 14400
#      Thu Jul 23 14:00:03 2015 -0400
# Node ID 57ac65580b5bba0cb4bb61dca9d63daec0ceb14c
# Parent  341e4303d25be159d4773b819d0ec055ba711afb
Workaround for "configuration file test failed" under OpenVZ.

nginx configuration test failed:

# 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

...if nginx used under OpenVZ and container with nginx was suspended and 
resumed.

After this patch - nginx configuration test works fine under 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

PS More details about OpenVZ suspend/resume bug:
https://bugzilla.openvz.org/show_bug.cgi?id=2470

diff -r 341e4303d25b -r 57ac65580b5b src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Thu Jul 16 14:20:48 2015 +0300
+++ b/src/core/ngx_connection.c Thu Jul 23 14:00:03 2015 -0400
@@ -567,9 +567,13 @@
  #endif

              if (listen(s, ls[i].backlog) == -1) {
-                ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
-                              "listen() to %V, backlog %d failed",
-                              &ls[i].addr_text, ls[i].backlog);
+                err = ngx_socket_errno;
+
+                if (err != NGX_EADDRINUSE || !ngx_test_config) {
+                    ngx_log_error(NGX_LOG_EMERG, log, err,
+                                  "listen() to %V, backlog %d failed",
+                                  &ls[i].addr_text, ls[i].backlog);
+                }

                  if (ngx_close_socket(s) == -1) {
                      ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
@@ -577,7 +581,15 @@
                                    &ls[i].addr_text);
                  }

-                return NGX_ERROR;
+                if (err != NGX_EADDRINUSE) {
+                    return NGX_ERROR;
+                }
+
+                if (!ngx_test_config) {
+                    failed = 1;
+                }
+
+                continue;
              }

              ls[i].listen = 1;

-------------- next part --------------
# HG changeset patch
# User Gena Makhomed <gmm at csdoc.com>
# Date 1437674403 14400
#      Thu Jul 23 14:00:03 2015 -0400
# Node ID 57ac65580b5bba0cb4bb61dca9d63daec0ceb14c
# Parent  341e4303d25be159d4773b819d0ec055ba711afb
Workaround for "configuration file test failed" under OpenVZ.

nginx configuration test failed:

# 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

...if nginx used under OpenVZ and container with nginx was suspended and resumed.

After this patch - nginx configuration test works fine under 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

PS More details about OpenVZ suspend/resume bug:
https://bugzilla.openvz.org/show_bug.cgi?id=2470

diff -r 341e4303d25b -r 57ac65580b5b src/core/ngx_connection.c
--- a/src/core/ngx_connection.c	Thu Jul 16 14:20:48 2015 +0300
+++ b/src/core/ngx_connection.c	Thu Jul 23 14:00:03 2015 -0400
@@ -567,9 +567,13 @@
 #endif
 
             if (listen(s, ls[i].backlog) == -1) {
-                ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
-                              "listen() to %V, backlog %d failed",
-                              &ls[i].addr_text, ls[i].backlog);
+                err = ngx_socket_errno;
+
+                if (err != NGX_EADDRINUSE || !ngx_test_config) {
+                    ngx_log_error(NGX_LOG_EMERG, log, err,
+                                  "listen() to %V, backlog %d failed",
+                                  &ls[i].addr_text, ls[i].backlog);
+                }
 
                 if (ngx_close_socket(s) == -1) {
                     ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
@@ -577,7 +581,15 @@
                                   &ls[i].addr_text);
                 }
 
-                return NGX_ERROR;
+                if (err != NGX_EADDRINUSE) {
+                    return NGX_ERROR;
+                }
+
+                if (!ngx_test_config) {
+                    failed = 1;
+                }
+
+                continue;
             }
 
             ls[i].listen = 1;


More information about the nginx-devel mailing list