comalex3 comalex3 - 3 days ago 4
Python Question

why do i have error "Address already in use"?

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

Answer

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()

Comments