Quick successive reload makes "bind () xxxx failed, Address already in use" error

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Quick successive reload makes "bind () xxxx failed, Address already in use" error

he.hailong5
Hi,



I have a script runs two successive reloads, the first one is to remove a listen port from the stream block, and the second one is to add the same port back to the stream block. It is observed that most time the script would run into "bind() xxxx failed, Address already in use" error. After putting a sleep 1 in between these two reloads I never get that error again.


So I guess the listening socket was not released in the time the second reload was issued?


How the listening socket is getting released during reload?


In this case, how to ensure that we can safely trigger the second reload other than sleep?






br,


Allen
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick successive reload makes "bind () xxxx failed, Address already in use" error

方坤
Kill old processes first, then start new processes.

On Wed, Jan 24, 2018 at 11:13 AM, <[hidden email]> wrote:

Hi,

I have a script runs two successive reloads, the first one is to remove a listen port from the stream block, and the second one is to add the same port back to the stream block. It is observed that most time the script would run into "bind() xxxx failed, Address already in use" error. After putting a sleep 1 in between these two reloads I never get that error again. 

So I guess the listening socket was not released in the time the second reload was issued? 

How the listening socket is getting released during reload?

In this case, how to ensure that we can safely trigger the second reload other than sleep?


br,

Allen







_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick successive reload makes "bind () xxxx failed, Address already in use" error

Zhang Chao
In reply to this post by he.hailong5
Hello!

> I have a script runs two successive reloads, the first one is to remove a listen port from the stream block, and the second one is to add the same port back to the stream block. It is observed that > most time the script would run into "bind() xxxx failed, Address already in use" error. After putting a sleep 1 in between these two reloads I never get that error again. 

How does you send “reload” command? Through the nginx -s reload or sending signal to the master process directly?

> So I guess the listening socket was not released in the time the second reload was issued? 

> How the listening socket is getting released during reload?

The old unnecessary listening sockets will be closed after nginx master process opens the new listening sockets.


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick successive reload makes "bind () xxxx failed, Address already in use" error

oscaretu .
In reply to this post by he.hailong5
If you search in Google

    detect a IP port is in use in linux

you can find several ways to detect in the port is in use, for Windows and Unix

Kindl regards,

Oscar


Virus-free. www.avast.com

On Wed, Jan 24, 2018 at 8:01 AM, <[hidden email]> wrote:
The downtime is critical, we cannot take "Kill and Start process"
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx



--
Oscar Fernandez Sierra
[hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick successive reload makes "bind () xxxx failed, Address already in use" error

he.hailong5
In reply to this post by he.hailong5
This is the forever loop that it it running in the script






for {


  nginx -s reload //without the port


  nginx -s reload //with the port


}






I found there was a transient that both the master process and the newly forked worker were listening the same port, I am not sure if this mgiht cause the "bind" error.


Another fact is that the port is listening after the "bind" error was occurring, so this was not due to the "delete" was not completed that makes the "add" not success.


I am wondering how this "bind" error happens?






Br,


Allen
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick successive reload makes "bind () xxxx failed, Address already in use" error

Francis Daly
In reply to this post by he.hailong5
On Wed, Jan 24, 2018 at 11:13:54AM +0800, [hidden email] wrote:

Hi there,

> I have a script runs two successive reloads, the first one is to remove a listen port from the stream block, and the second one is to add the same port back to the stream block.

Why?

If it is "I want to see what happens when I do that", that's perfectly
fine; carry on with the research.

If it is "I want to achieve some other objective, and this is a step
that I think is necessary", then perhaps there is an alternative way to
achieve that objective.

Cheers,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx