12

i run my flask app, and it works good, but by the time the app is stopped and in my uwsgi log

probably another instance of uWSGI is running on the same address (127.0.0.1:9002).
 bind(): Address already in use [core/socket.c line 764]

when i run touch touch_reload, app is working again. I run anything else on the server which may take the socket.

my conf:

nginx
server {
 listen 80;
 ....
 location / {
 include uwsgi_params;
 uwsgi_pass 127.0.0.1:9001;
 }
 ....
}
server {
 listen 80;
 ....
 location / {
 include uwsgi_params;
 uwsgi_pass 127.0.0.1:9003;
 }
 ....
}
uwsgi:
chdir = /var/www/../
module = wsgihandler
socket = 127.0.0.1:9003
wsgi-file = app/__init__.py
callable = app
master = true
chmod-socket = 664
uid = root
gid = root
processes = 4
socket-timeout = 180
post-buffering = 8192
max-requests = 1000
buffer-size = 32768
logto = /var/www/.../log/uwsgi.log
touch-reload = /var/www/.../touch_reload
asked Jun 18, 2015 at 6:08
5
  • 4
    It means port 9002 is already in use. Commented Jun 18, 2015 at 6:09
  • How are you stopping the process? Commented Jun 18, 2015 at 6:15
  • You probably must be using ctrl+z to stop the process but that is actually just hiding it. use ctrl+c to entirely stop Commented Jun 18, 2015 at 6:31
  • additionally you can use ps aux | grep 9002 to see what are using 9002 for Commented Jun 18, 2015 at 6:32
  • I did not stop the server, it is production Commented Jun 18, 2015 at 10:12

6 Answers 6

15

This error means that port 9002 is already in use by another process. As per your logs that process is uwsgi probably another instance of uWSGI is running on the same address (127.0.0.1:9002). May be the port was not released while you stop flask app and your wsgi server is restarted while you run touch touch_reload. You may try the following command to release the port.

sudo fuser -k 9002/tcp

If that is a tcp process and restart your wsgi server again to see if the port is already in use.

answered Jun 18, 2015 at 6:13
Sign up to request clarification or add additional context in comments.

Comments

10

maybe you stop uwsgi by crtl + z:

  1. find the pid of process which take 8000

$ lsof -i:8000

result maybe is:

COMMAND PID USER FD TYPE ...
uwsgi 9196 xxx 4u xxx ...

then

$ kill 9196

answered Aug 8, 2017 at 8:47

1 Comment

It could also be useful(necessary) to use -9: ` kill -9 9196`
2

i have same issue, but the problem was in sqlalchemy, try to add this:

@app.teardown_request
def shutdown_session(exception=None):
 from extension import db
 db.session.remove()
xyres
22k5 gold badges64 silver badges89 bronze badges
answered Jul 14, 2015 at 15:51

Comments

2

FWIW, I had a similar issue and discovered that I was running uwsgi --http when I should have been running uwsgi --socket.

answered Jun 11, 2018 at 15:30

Comments

1

Interestingly, you will get the same Address already in use error, even if you work with sockets.

 vvvvvvvvvvv-- Socket!
error removing unix socket, unlink(): Permission denied [core/socket.c line 198]
bind(): Address already in use [core/socket.c line 230]
 ^^^^^^^^^^^^^^^-- "Address"

If you DO use sockets, see this answer.

answered Jul 19, 2018 at 7:51

Comments

0

I had the same problem, and it turned out my main module was already starting the application with app.run() on load.

So make sure app.run() is in the if __name__ == '__main__' section.

answered Dec 1, 2016 at 11:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.