Why can't I start my gunicorn server? "Connection in use"
Asked Answered
D

7

30

Any ideas why my gunicorn server won't start?

jeffy@originaldjangster:~$ sudo /home/jeffy/django_files/django_test_venv/bin/gunicorn -c /home/jeffy/django_files/django_test_venv/gunicorn_config.py django_test.wsgi
 Connection in use: ('127.0.0.1', 8001)
 Retrying in 1 second.
 Connection in use: ('127.0.0.1', 8001)
 Retrying in 1 second.
 Connection in use: ('127.0.0.1', 8001)
 Retrying in 1 second.
 Connection in use: ('127.0.0.1', 8001)
 Retrying in 1 second.
 Connection in use: ('127.0.0.1', 8001)
 Retrying in 1 second.
 Can't connect to ('127.0.0.1', 8001)
jeffy@originaldjangster:~$

nginx listens to http://104.131.200.120/, and passes to gunicorn, which listens to 127.0.0.1. I'm on Ubuntu 14.

I've listed all processes to see if gunicorn was already running:

jeffy@originaldjangster:~$ ps -a
   PID TTY          TIME CMD
  7653 pts/1    00:00:00 ps
 jeffy@originaldjangster:~$ ps
   PID TTY          TIME CMD
  7249 pts/1    00:00:00 bash
  7654 pts/1    00:00:00 ps
 jeffy@originaldjangster:~$ ps -A
   PID TTY          TIME CMD
     1 ?        00:00:02 init
     2 ?        00:00:00 kthreadd
     3 ?        00:00:00 ksoftirqd/0
     5 ?        00:00:00 kworker/0:0H
     6 ?        00:00:00 kworker/u2:0
     7 ?        00:00:00 rcu_sched
     8 ?        00:00:00 rcu_bh
     9 ?        00:00:00 migration/0
    10 ?        00:00:00 watchdog/0
    11 ?        00:00:00 khelper
    12 ?        00:00:00 kdevtmpfs
    13 ?        00:00:00 netns
    14 ?        00:00:00 writeback
    15 ?        00:00:00 kintegrityd
    16 ?        00:00:00 bioset
    17 ?        00:00:00 kworker/u3:0
    18 ?        00:00:00 kblockd
    19 ?        00:00:00 ata_sff
    20 ?        00:00:00 khubd
    21 ?        00:00:00 md
    22 ?        00:00:00 devfreq_wq
    23 ?        00:00:08 kworker/0:1
    24 ?        00:00:00 khungtaskd
    25 ?        00:00:00 kswapd0
    26 ?        00:00:00 ksmd
    27 ?        00:00:00 fsnotify_mark
    28 ?        00:00:00 ecryptfs-kthrea
    29 ?        00:00:00 crypto
    41 ?        00:00:00 kthrotld
    44 ?        00:00:00 scsi_eh_0
    45 ?        00:00:00 scsi_eh_1
    66 ?        00:00:00 deferwq
    67 ?        00:00:00 charger_manager
   120 ?        00:00:01 jbd2/vda-8
   121 ?        00:00:00 ext4-rsv-conver
   271 ?        00:00:00 upstart-udev-br
   275 ?        00:00:00 systemd-udevd
   322 ?        00:00:00 dbus-daemon
   349 ?        00:00:00 kpsmoused
   351 ?        00:00:00 kworker/0:2
   356 ?        00:00:00 systemd-logind
   358 ?        00:00:00 rsyslogd
   387 ?        00:00:00 kvm-irqfd-clean
   624 ?        00:00:00 upstart-file-br
   704 ?        00:00:00 upstart-socket-
   758 tty4     00:00:00 getty
   761 tty5     00:00:00 getty
   767 tty2     00:00:00 getty
   768 tty3     00:00:00 getty
   770 tty6     00:00:00 getty
   794 ?        00:00:00 sshd
   800 ?        00:00:00 acpid
   802 ?        00:00:00 cron
   804 ?        00:00:00 atd
   853 ?        00:00:01 postgres
   855 ?        00:00:00 postgres
   856 ?        00:00:01 postgres
   857 ?        00:00:01 postgres
   858 ?        00:00:02 postgres
   859 ?        00:00:02 postgres
   903 ?        00:00:17 supervisord
   961 tty1     00:00:00 getty
   982 ?        00:00:00 kauditd
  1266 ?        00:00:07 kworker/u2:1
  3027 ?        00:00:00 kworker/u3:1
  3230 ?        00:00:00 sudo
  3231 ?        00:00:01 gunicorn
  7014 ?        00:00:00 gunicorn
  7115 ?        00:00:00 sshd
  7192 ?        00:00:00 sshd
  7193 ?        00:00:00 sftp-server
  7200 ?        00:00:00 sshd
  7248 ?        00:00:00 sshd
  7249 pts/1    00:00:00 bash
  7610 ?        00:00:00 nginx
  7613 ?        00:00:00 nginx
  7614 ?        00:00:00 nginx
  7615 ?        00:00:00 nginx
  7616 ?        00:00:00 nginx
  7649 ?        00:00:00 sshd
  7650 ?        00:00:00 sshd
 7655 pts/1    00:00:00 ps

Here's the two gunicorn lines:

  3231 ?        00:00:01 gunicorn
  7014 ?        00:00:00 gunicorn

I've tried to kill those two processes, but when bringing them to the foreground with fg 3231, for example, it says "no such job".

Someone suggested I try netstat -aWn --programs | grep 80. Here is the result, which I don't understand

jeffy@originaldjangster:~$ sudo netstat -aWn --programs | grep 80
 tcp        0      0 127.0.0.1:8001          0.0.0.0:*               LISTEN      3231/python3.4
 unix  2      [ ACC ]     STREAM     LISTENING     8911     800/acpid           /var/run/acpid.socket
 unix  2      [ ]         DGRAM                    8908     800/acpid

Any ideas what is causing this "connection in use" error? Thanks.

Deathblow answered 10/8, 2014 at 16:30 Comment(1)
Thanks for "netstat -aWn --programs | grep 80" - saved me!Cartoon
D
20

Turns out I just needed to sudo kill 3231 and sudo kill 7014. I incorrectly thought they first needed to brought to the foreground. The fact that the processes couldn't be seen until I used the capital A option (ps -A) mislead me, that they were somehow special.

The server was running (in the foreground) when I went to sleep before my wife. She turned off the computer before going to bed.

Ubuntu and gunicorn Newbie. Could you tell?

Deathblow answered 10/8, 2014 at 16:30 Comment(2)
i don't have gunicorn in the list when I use ps -A. But I'm getting the same error. Any ideas?Cunaxa
Worked perfectly for me - accidentally closed the window my heroku local web was running in, but that apparently does NOT close gunicorn; this did the trick, and I'm back to making my webpages. Thanks!Banderillero
V
19

I have gotten used to run killall gunicorn before (re)starting Gunicorn in my local development environment.

Venesection answered 26/3, 2020 at 7:44 Comment(0)
M
10

I've found my solution here.

ps ax|grep gunicorn
>>> 932 pts/0    S      0:01 /home/someuser/flaskdir/.venv/bin/python3 /home/someuser/flaskdir/.venv/bin/gunicorn -w 3 flaskapp:app

kill -9 932
Mindy answered 6/6, 2021 at 10:18 Comment(0)
O
8

For anyone who has nothing running on the port to kill, if app.run() is in the file gunicorn is running, then it will run twice on the port and keep attempting to retry the connection.

In my case, I was running $ gunicorn run:app where run.py had: from app import app app.run(debug=True)

in it. When I commented out the app.run, it worked.

Oxalis answered 18/1, 2021 at 6:2 Comment(0)
J
2

This worked for me:

sudo fuser -k 8000/tcp
Jakie answered 23/1, 2023 at 20:16 Comment(0)
P
1

Restarting the computer helped for me

  • I did not have gunicorn in listing of ps -A so I did not know what to kill
  • I also did not get anything obvious from netstat -aWn --programs | grep 80
Petite answered 9/10, 2018 at 9:18 Comment(1)
Same problem in appengine standard env, runtime python37. Now how can we slove thisScots
Q
-1

I also came across same problem ... Dont try to run gunicorn from su . Just change user and try again

Quietude answered 18/1, 2018 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.