I am unable to start my bench - bind: Address already in use

administrator@Server:~/erpnext$ bench start
16:56:14 system | redis_socketio.1 started (pid=8172)
16:56:14 system | worker_long.1 started (pid=8174)
16:56:14 system | watch.1 started (pid=8176)
16:56:14 system | web.1 started (pid=8179)
16:56:14 system | redis_queue.1 started (pid=8177)
16:56:14 system | schedule.1 started (pid=8180)
16:56:14 redis_socketio.1 | 8184:M 29 Sep 16:56:14.894 * Increased maximum number of open files to 10032 (it was originally set to 1024).
16:56:14 system | worker_default.1 started (pid=8181)
16:56:14 system | socketio.1 started (pid=8187)
16:56:14 redis_socketio.1 | 8184:M 29 Sep 16:56:14.894 # Creating Server TCP listening socket 127.0.0.1:12000: bind: Address already in use
16:56:14 system | redis_socketio.1 stopped (rc=1)
16:56:14 redis_queue.1 | 8193:M 29 Sep 16:56:14.896 * Increased maximum number of open files to 10032 (it was originally set to 1024).
16:56:14 redis_queue.1 | 8193:M 29 Sep 16:56:14.896 # Creating Server TCP listening socket 127.0.0.1:11000: bind: Address already in use
16:56:14 system | redis_queue.1 stopped (rc=1)
16:56:14 system | redis_cache.1 started (pid=8186)
16:56:14 system | worker_short.1 started (pid=8190)
16:56:14 system | sending SIGTERM to worker_long.1 (pid 8174)
16:56:14 system | sending SIGTERM to watch.1 (pid 8176)
16:56:14 system | sending SIGTERM to web.1 (pid 8179)
16:56:14 system | sending SIGTERM to schedule.1 (pid 8180)
16:56:14 system | sending SIGTERM to worker_default.1 (pid 8181)
16:56:14 system | sending SIGTERM to socketio.1 (pid 8187)
16:56:14 system | sending SIGTERM to redis_cache.1 (pid 8186)
16:56:14 system | sending SIGTERM to worker_short.1 (pid 8190)
16:56:14 redis_cache.1 | 8202:signal-handler (1538220374) Received SIGTERM scheduling shutdown…
16:56:14 redis_cache.1 | 8202:M 29 Sep 16:56:14.900 * Increased maximum number of open files to 10032 (it was originally set to 1024).
16:56:14 system | worker_long.1 stopped (rc=-15)
16:56:14 system | worker_short.1 stopped (rc=-15)
16:56:14 system | web.1 stopped (rc=-15)
16:56:14 system | schedule.1 stopped (rc=-15)
16:56:14 system | watch.1 stopped (rc=-15)
16:56:14 redis_cache.1 | 8202:M 29 Sep 16:56:14.901 # Creating Server TCP listening socket 127.0.0.1:13000: bind: Address already in use
16:56:14 system | redis_cache.1 stopped (rc=-15)
16:56:14 system | worker_default.1 stopped (rc=-15)
16:56:14 system | socketio.1 stopped (rc=-15)
administrator@Server:~/erpnext$

pls help

You can see that your port is already in use.

  1. sudo supervisorctl stop all
  2. sudo service nginx stop
  3. bench start
2 Likes

not working same error

is there any other server working on Same port?

Make sure you tried all the command successfully.

administrator@Server:~/erpnext$ sudo supervisorctl stop all
unix:///var/run/supervisor.sock no such file
administrator@Server:~/erpnext$ sudo service nginx stop
administrator@Server:~/erpnext$ bench start
17:47:31 system | redis_socketio.1 started (pid=11568)
17:47:31 system | watch.1 started (pid=11572)
17:47:31 system | redis_queue.1 started (pid=11574)
17:47:31 system | web.1 started (pid=11575)
17:47:31 system | worker_long.1 started (pid=11570)
17:47:31 system | worker_default.1 started (pid=11577)
17:47:31 redis_socketio.1 | 11581:M 29 Sep 17:47:31.757 * Increased maximum number of open files to 10032 (it was originally set to 1024).
17:47:31 redis_socketio.1 | 11581:M 29 Sep 17:47:31.757 # Creating Server TCP listening socket 127.0.0.1:12000: bind: Address already in use
17:47:31 redis_queue.1 | 11584:M 29 Sep 17:47:31.758 * Increased maximum number of open files to 10032 (it was originally set to 1024).
17:47:31 system | redis_socketio.1 stopped (rc=1)
17:47:31 redis_queue.1 | 11584:M 29 Sep 17:47:31.758 # Creating Server TCP listening socket 127.0.0.1:11000: bind: Address already in use
17:47:31 system | socketio.1 started (pid=11579)
17:47:31 system | redis_queue.1 stopped (rc=1)
17:47:31 system | redis_cache.1 started (pid=11590)
17:47:31 system | schedule.1 started (pid=11576)
17:47:31 system | worker_short.1 started (pid=11591)

if not enable:
sudo systemctl enable supervisor

or

sudo service supervisor stop
sudo service supervisor start

Regarding your issue, 127.0.0.1:12000 and 127.0.0.1:11000 are already used, type sudo lsof -i -P -n | grep LISTEN to know the used IP addresses, and show the output then kill it manually, if nothing important is using it kill it so that supervisor uses that IP address
netstat -lnp | grep 'tcp .*IPADDRESS:PORT' | sed -e 's/.*LISTEN *//' -e 's#/.*##' | xargs kill this is not a very clean way, but it works

Rebooting the OS might work sometimes, because you will start fresh, but that’s a lazy solution, and you wouldn’t know what is the cause and how you solved the issue.

2 Likes

Thnx for your support

Solution that worked for me:

“sudo lsof -t -i tcp:12000 -s tcp:listen | sudo xargs kill”

Note: This command is used to kill any process running on the said port. Tip: Replace the port number with the one from the error

2 Likes

it works thanks

Restart OS

and

start bench

is the easiest way.


I had the same problem. The issue was when I tried to use bench start. The bench was already started. I didn't have supervisor or nginx installed. When I checked the website, I found that the website was fine. Of course, The next step was to install supervisor and nginx.

I had the same problem. The issue was when I tried to use bench start. The bench was already started. I didn’t have supervisor or nginx installed. When I checked the website, I found that the website was fine. Of course, The next step was to install supervisor and nginx.

Yea, reboot, it’s the linux way. :smile:

This was my solution. I had a test server that I was debugging on. The Office VPN dropped while in the middle of debugging.

Oddly, I had a redis service running under the ‘erp’ account that didn’t stop with supervisorctl or with systemctl.

Rebooting did fix it. I wonder if the previous bench start console was somehow running in a nohup mode or something.

I didn’t try killing the rogue processes, that would have probably fixed it without the reboot. I was worried that bench start had created a phantom terminal somewhere, so reboot cleaned it all out.

That might explain why the normal method works most of the time - but not always.

    == John ==
#!/usr/bin/env python3

""" stop.py is an attempt at creating an easy 'bench stop' command

    Possible improvements:
    - Refactor code and merge with bench 
    - check for production where stop command will use supervisor
    - check for non-ubuntu platforms
"""


import os, socket, errno, time

# Declaring part of ports.
# Getting port suffix from current  redis config.
ports = [1100, 1200, 1300, 900, 800, 500]
lines = {}
port_suffix = 0;
sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
  with open("./config/redis_cache.conf") as config_file:
      for line in config_file:
          key, value = line.partition(" ")[::2]
          lines[key.strip()] = value.strip()
      port_suffix =  lines["port"][-1:]
  config_file.close()
except IOError:
    print('The file redis_cache.conf was not found. Are you sure you stop.py is in bench directory?')
    exit();

# Closing open ports after combining each port prefix and suffix
for port in ports:
  port = int("".join([str(port), str(port_suffix)]))
  try:
    sockets.bind(("127.0.0.1", port))
  except socket.error as e:

    if e.errno == errno.EADDRINUSE:
      os.system("echo 'shutdown' | redis-cli -h 127.0.0.1 -p %d" % port)
      time.sleep(3)

      try:
        sockets.bind(("127.0.0.1", port))
      except socket.error as e:
        if e.errno == errno.EADDRINUSE:
          os.system("fuser %d/tcp -k" % port)
        else:
          print ('Port %d' % port, 'now closed')

  else:
    print ('Port %d' % port, 'already closed')
    sockets.close()
    sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    continue

sockets.close()

print ('bench stopped')

Usage:

admin@erpls:~/frappe-bench-ERPLS$ chmod +x stop.py 
admin@erpls:~/frappe-bench-ERPLS$ ./stop.py 
11000/tcp:           16180
12000/tcp:           16193
13000/tcp:           16208
9000/tcp:            16076
8000/tcp:            16075 16163 16164 16165 16166 16167 16172 16173 16174 16175
5000/tcp:            16153
bench stopped
admin@erpls:~/frappe-bench-ERPLS$ 

My solution are:

  • find ports:
 lsof -i -P -n | grep LISTEN
  • kill them (11000, 12000, 13000, 8000, 9000):
 sudo lsof -t -i tcp:<PORT> -s tcp:listen | sudo xargs kill
3 Likes

I have remembered the actual origin of the code.

Please see :

It refers to the published code here:

1 Like

bind: Address already in use issue

1.sudo supervisorctl stop all
2.sudo service nginx stop
3.bench start

2 Likes

This solved my problem

If you have installed in Linux and if in any point in time bind address 11000 to redis server teh culprit would be redis server.

stop redis using systemctl stop redis and then try.

This is working for ubuntu 22.04 and mariadb10.6

1 Like