unix sockets are not reused when restarting nginx

Maxim Dounin mdounin at mdounin.ru
Mon May 21 13:27:35 UTC 2018


Hello!

On Sun, May 20, 2018 at 01:20:07PM +0300, Volodymyr Kostyrko wrote:

> Hello.
> 
> I'm using nginx 1.14.0 on FreeBSD 11-STABLE. I'm trying to get caching 
> for internally generated content so I'm proxying nginx to nginx:
> 
> server {
>          listen unix:/home/someuser/.media.nginx.sock;
> 
>> }
> 
> This perfectly works when starting nginx initially. However when 
> restarting I sometimes get error reopening sockets to serve them:
> 
> nginx.error.log:2018/05/14 02:05:30 [emerg] 3583#0: bind() to 
> unix:/home/someuser/.site.nginx.sock failed (48: Address already in use)
> nginx.error.log:2018/05/14 02:05:30 [emerg] 3583#0: bind() to 
> unix:/home/someuser/.site.nginx.sock failed (48: Address already in use)
> nginx.error.log:2018/05/14 02:05:30 [emerg] 3583#0: bind() to 
> unix:/home/someuser/.site.nginx.sock failed (48: Address already in use)
> nginx.error.log:2018/05/14 02:05:30 [emerg] 3583#0: bind() to 
> unix:/home/someuser/.site.nginx.sock failed (48: Address already in use)
> nginx.error.log:2018/05/14 02:05:30 [emerg] 3583#0: bind() to 
> unix:/home/someuser/.site.nginx.sock failed (48: Address already in use)
> 
> This can happen even on boot. Removing sockets allows nginx to start.

Check how do you stop nginx.

nginx removes unix sockets when it is stopped using the TERM and 
INT signals (fast shutdown), but not when it is stopped gracefully 
using the QUIT signal (graceful shutdown, see 
http://nginx.org/en/docs/control.html).  This is because graceful 
shutdown is normally used during binary upgrade, and open 
listening sockets are passed to the new master process, so 
removing them will break things.  If you are using graceful 
shutdown for other purposes than during binary upgrade for some 
reason, you have to remove listening unix sockets yourself.

> I also got this error:
> 
> error.log:2018/05/07 16:07:49 [notice] 89443#0: getsockopt(TCP_FASTOPEN) 
> unix:/home/someuser/.site.nginx.sock failed, ignored (22: Invalid argument)

This is safe to ignore.  The following patch will hide this 
notice:

diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -305,7 +305,9 @@ ngx_set_inherited_sockets(ngx_cycle_t *c
         {
             err = ngx_socket_errno;
 
-            if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT) {
+            if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT
+                && err != EINVAL)
+            {
                 ngx_log_error(NGX_LOG_NOTICE, cycle->log, err,
                               "getsockopt(TCP_FASTOPEN) %V failed, ignored",
                               &ls[i].addr_text);


-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list