# 98: Address already in use

**URL:** <https://www.ruby-forum.com/t/98-address-already-in-use/205734>\
**Category:** NGINX\
**Created:** [April 14, 2011, 2:04pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734 "2011-04-14T14:04:39Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 14, 2011, 2:04pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/1 "2011-04-14T14:04:39Z")

</div>

Hi all,

Nginx has been working fine for months on my server. Recently, however,  
I see that “service nginx configtest” reports the following:

the configuration file /etc/nginx/nginx.conf syntax is ok  
[emerg]: listen() to 0.0.0.0:17942, backlog 511 failed (98: Address  
already in use)  
configuration file /etc/nginx/nginx.conf test failed

I believe nginx has been updated recently, but I’m not sure. It’s  
currently at version 0.8.53. I’ve ran configtest before and have never  
seen this error. I need to add a new site in conf.d, but I fear that  
reloading or restarting afterwards will fail and my live sites will be  
down.

netstat -tlnp lists 0.0.0.0:17942 as in use by Program name “nginx.conf”  
(which seems weird, shouldn’t this just say “nginx”). Also, if I rename  
the conf.d/site.conf file that includes the 17942 port entry, it just  
fails on the next conf down the line on the following ip/port.

Now that I’ve typed out the entire problem, it occurs to me that the  
problem could be the misnamed Program name. Maybe nginx thinks that a  
different program is occupying those ports because the name is not  
“nginx”. Does that seem likely? Also, was there a bug fixed somewhere  
that resolved/caused the name change? I have a hunch that restarting  
nginx will solve the problem, but I don’t want to risk it since it’s a  
live server.

Any ideas? Thank you for reading.

Posted at Nginx Forum:

> **[98: Address already in use](https://forum.nginx.org/read.php?2,191227,191227#msg-191227)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 14, 2011, 3:59pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/2 "2011-04-14T15:59:05Z")

</div>

Hello!

On Thu, Apr 14, 2011 at 08:04:03AM -0400, slowgary wrote:

> Hi all,
> 
> Nginx has been working fine for months on my server. Recently, however,  
> I see that “service nginx configtest” reports the following:
> 
> the configuration file /etc/nginx/nginx.conf syntax is ok  
> [emerg]: listen() to 0.0.0.0:17942, backlog 511 failed (98: Address  
> already in use)  
> configuration file /etc/nginx/nginx.conf test failed

Could you please provide details about OS you use?

EADDRINUSE should occur on bind() syscall earlier, and it’s  
correctly handled there (ignored during configuration testing, and  
no listen() call done).

> I believe nginx has been updated recently, but I’m not sure. It’s  
> currently at version 0.8.53. I’ve ran configtest before and have never  
> seen this error. I need to add a new site in conf.d, but I fear that  
> reloading or restarting afterwards will fail and my live sites will be  
> down.

Reload/restart will likely succeed - listen() shouldn’t be even  
called in your situation normally. It’s not clear why bind()  
doesn’t report the same error though, most likely something  
OS-related.

> nginx will solve the problem, but I don’t want to risk it since it’s a  
> live server.

Name reported by netstat is completely unrelated (and it’s not  
under nginx control).

Maxim D.

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 14, 2011, 4:21pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/3 "2011-04-14T16:21:18Z")

</div>

The OS is Centos 5.6 (Final)

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,191272#msg-191272)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 14, 2011, 7:47pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/4 "2011-04-14T19:47:46Z")

</div>

## Hello, could you stop nginx and check whats running on port 80? by:\* lsof -i :80\* or netstat -antp|grep 80

Hseyin Mert  
[http://www.hmert.com](http://www.hmert.com)

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 14, 2011, 8:20pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/5 "2011-04-14T20:20:31Z")

</div>

“netstat -antp | grep 80” output can be found at:

> **[tcp 0 0 12.34.56.78:80 0.0.0.0:\* ...](https://pastebin.com/gtBUPckV)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Thanks.

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,191349#msg-191349)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 14, 2011, 5:15pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/6 "2011-04-14T17:15:08Z")

</div>

I don’t think it has anything to do with my configs, since things have  
been working correctly for a long time. Just in case though, you can  
see them here:

nginx.conf

> **[user nginx;worker\_processes	2;error\_log /var/log/nginx/error.log;pid -...](https://pastebin.com/bJeur7Bq)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

mydomain.conf

> **[server {	listen 80;	server\_name mydomain.com;	rewrite ^ $scheme://www. -...](https://pastebin.com/rAMuKgug)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Thanks again.

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,191291#msg-191291)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 14, 2011, 8:40pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/7 "2011-04-14T20:40:56Z")

</div>

On 14 Abr 2011 19h21 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry, I forgot to mention that I did not stop nginx. There are  
> live sites hosted on this server. My ultimate goal here is to avoid  
> downtime, otherwise I would definitely restart nginx to see what  
> happens.

There’s no downtime if you restart it properly: See

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

— appa

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 15, 2011, 8:31am UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/8 "2011-04-15T08:31:05Z")

</div>

On Thu, Apr 14, 2011 at 08:04:03AM -0400, slowgary wrote:

> Now that I’ve typed out the entire problem, it occurs to me that the  
> problem could be the misnamed Program name. Maybe nginx thinks that a  
> different program is occupying those ports because the name is not  
> “nginx”. Does that seem likely? Also, was there a bug fixed somewhere  
> that resolved/caused the name change? I have a hunch that restarting  
> nginx will solve the problem, but I don’t want to risk it since it’s a  
> live server.

Could you show output of  
ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep ‘(nginx|PID)’

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 14, 2011, 8:21pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/9 "2011-04-14T20:21:45Z")

</div>

Sorry, I forgot to mention that I did not stop nginx. There are live  
sites hosted on this server. My ultimate goal here is to avoid  
downtime, otherwise I would definitely restart nginx to see what  
happens.

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,191350#msg-191350)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 15, 2011, 11:19am UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/10 "2011-04-15T11:19:13Z")

</div>

PID PPID %CPU VSZ WCHAN COMMAND  
1867 1 0.0 14248 rt\_sig nginx: master process /usr/sbin/nginx -c  
/etc/nginx/nginx.conf  
22231 1867 0.2 18704 - nginx: worker process  
22232 1867 0.2 27852 - nginx: worker process  
32653 32619 0.0 1932 pipe\_w egrep (nginx|PID)

Thanks Igor.

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,191456#msg-191456)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 15, 2011, 6:18pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/11 "2011-04-15T18:18:15Z")

</div>

Hello!

On Thu, Apr 14, 2011 at 10:20:31AM -0400, slowgary wrote:

> The OS is Centos 5.6 (Final)

Looking though linux code and testing on the exactly same centos -  
it seems that linux may indeed return EADDRINUSE on listen().

But as far as I see the only situation when it may appear is two  
bind()'s on conflicting ports followed by two listen()'s. Second  
listen() call will fail with EADDRINUSE.

This shouldn’t happen in nginx unless you are running something  
with 3rd party patches (or there is some other programm doing  
bind()/listen() on the same ports, but this is racy and really  
unlikely to be reproduceable).

Could you please show full config (with all listen’s - the only  
you’ve provided seems not contain ports you see in complaints at  
all…), “nginx -V” output and “nginx -t” output (this should be  
identical to “service nginx configtest”, but just in case)?

Maxim D.

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 19, 2011, 3:15pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/12 "2011-04-19T15:15:22Z")

</div>

Last night I stopped and started nginx and it resolved the issue.

nginx -t  
the configuration file /etc/nginx/nginx.conf syntax is ok  
configuration file /etc/nginx/nginx.conf test is successful

It really seems that somehow nginx couldn’t realize that nginx itself  
was bound to those addresses.

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,192320#msg-192320)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 18, 2011, 7:23pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/13 "2011-04-18T19:23:34Z")

</div>

Thanks Maxim.

I installed nginx from the EPEL repo, I don’t know of any 3rd party  
patches. Is it common for 3rd party patched versions to exist in a  
repo? Also, my current configuration has worked fine for months. I  
believe this problem may have started after upgrading from CentOS 5.5 to  
5.6.

=======================================================================  
nginx -V output:

nginx version: nginx/0.8.53  
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)  
TLS SNI support disabled  
configure arguments: --user=nginx --group=nginx  
–prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx  
–conf-path=/etc/nginx/nginx.conf  
–error-log-path=/var/log/nginx/error.log  
–http-log-path=/var/log/nginx/access.log  
–http-client-body-temp-path=/var/lib/nginx/tmp/client\_body  
–http-proxy-temp-path=/var/lib/nginx/tmp/proxy  
–http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi  
–http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi  
–http-scgi-temp-path=/var/lib/nginx/tmp/scgi  
–pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx  
–with-http\_ssl\_module --with-http\_realip\_module  
–with-http\_addition\_module --with-http\_xslt\_module  
–with-http\_image\_filter\_module --with-http\_geoip\_module  
–with-http\_sub\_module --with-http\_dav\_module --with-http\_flv\_module  
–with-http\_gzip\_static\_module --with-http\_random\_index\_module  
–with-http\_secure\_link\_module --with-http\_degradation\_module  
–with-http\_stub\_status\_module --with-http\_perl\_module --with-mail  
–with-file-aio --with-mail\_ssl\_module --with-ipv6 --with-cc-opt=‘-O2 -g  
-pipe -Wall -Wp,-D\_FORTIFY\_SOURCE=2 -fexceptions -fstack-protector  
–param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic  
-fasynchronous-unwind-tables’ --with-cc-opt=‘-O2 -g -pipe -Wall  
-Wp,-D\_FORTIFY\_SOURCE=2 -fexceptions -fstack-protector  
–param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic  
-fasynchronous-unwind-tables’

=======================================================================  
nginx -t output:

the configuration file /etc/nginx/nginx.conf syntax is ok  
[emerg]: listen() to 0.0.0.0:17942, backlog 511 failed (98: Address  
already in use)  
configuration file /etc/nginx/nginx.conf test failed

=======================================================================  
configs

fastcgi\_params

> **[fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;fastcgi\_p...](https://pastebin.com/bEYxpKhs)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

nginx.conf

> **[user nginx;worker\_processes	2;worker\_rlimit\_nofile	100000;error\_log /va -...](https://pastebin.com/MX3aLQk4)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

phpmyadmin.conf

> **[server {	listen 17942 default ssl;	server\_name 12.34.56.78;	root /var -...](https://pastebin.com/UKvq4xPY)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

mydomain1.conf  
[http://pastebin.com/r96E1Nmm](http://pastebin.com/r96E1Nmm)

mydomain2.conf  
[http://pastebin.com/Gku1irY1](http://pastebin.com/Gku1irY1)

shared\_rewrite\_rules

> **[\# canonicalize codeigniter url end points# if your default controller is somet...](https://pastebin.com/633reaxP)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Thank you for your help.

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,192126#msg-192126)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [October 11, 2013, 8:28pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/14 "2013-10-11T20:28:50Z")

</div>

I have the same problem and even if I stop nginx with /etc/init.d/nginx  
stop  
it is running on Debian Wheezy:

PID PPID %CPU VSZ WCHAN COMMAND  
2709 1 0.0 127476 ep\_pol nginx: worker process  
2710 1 0.0 127716 ep\_pol nginx: worker process  
2711 1 0.0 127476 ep\_pol nginx: worker process  
2713 1 0.0 127444 ep\_pol nginx: worker process  
2714 1 0.0 125208 ep\_pol nginx: cache manager process  
3458 3218 0.0 6392 pipe\_w egrep (nginx|PID)

Posted at Nginx Forum:

> **[Re: 98: Address already in use](https://forum.nginx.org/read.php?2,191227,243631#msg-243631)**
>
> Hi all, Nginx has been working fine for months on my server. Recently, however, I see that "service nginx configtest" reports the following: the configuration file /etc/nginx/nginx.conf syntax is ok \[emerg\]: listen() to 0.0.0.0:17942,...

---

<div class="post-metadata">

**Author:** ![slowgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@slowgary](https://www.ruby-forum.com/u/slowgary)\
**Post date:** [April 19, 2011, 5:21pm UTC](https://www.ruby-forum.com/t/98-address-already-in-use/205734/15 "2011-04-19T17:21:23Z")

</div>

Hello!

On Tue, Apr 19, 2011 at 09:14:48AM -0400, slowgary wrote:

> Last night I stopped and started nginx and it resolved the issue.
> 
> nginx -t  
> the configuration file /etc/nginx/nginx.conf syntax is ok  
> configuration file /etc/nginx/nginx.conf test is successful
> 
> It really seems that somehow nginx couldn’t realize that nginx itself  
> was bound to those addresses.

As I already said - the problem is that EADDRINUSE error was  
returned on listen() call for some reason, not on bind() as it  
should. This is itself POSIX violation, but I believe we don’t  
mind adding Linux-specific workaround if the problem is common and  
understood.

So the real question is “how this may happen?”. So far I wasn’t  
able to reproduce it even on exactly the same OS. Please let us  
know if you will be able to reproduce it.

Maxim D.
