Issues with gunicorn with my flaskapp

Hello, so I am in the process of deploying a flask app using nginx and gunicorn on a Linode server, I am relatively new to this so excuse any lack of detail if present.

The first issue I encountered was when I tried to use gunicorn to run my app with

gunicorn -w 3 run:app

I am given this response

[2020-09-24 16:37:05 +0000] [174092] [INFO] Starting gunicorn 20.0.4
[2020-09-24 16:37:05 +0000] [174092] [ERROR] Connection in use: ('127.0.0.1', 8000)
[2020-09-24 16:37:05 +0000] [174092] [ERROR] Retrying in 1 second.
[2020-09-24 16:37:06 +0000] [174092] [ERROR] Connection in use: ('127.0.0.1', 8000)
[2020-09-24 16:37:06 +0000] [174092] [ERROR] Retrying in 1 second.
[2020-09-24 16:37:07 +0000] [174092] [ERROR] Connection in use: ('127.0.0.1', 8000)
[2020-09-24 16:37:07 +0000] [174092] [ERROR] Retrying in 1 second.
[2020-09-24 16:37:08 +0000] [174092] [ERROR] Connection in use: ('127.0.0.1', 8000)
[2020-09-24 16:37:08 +0000] [174092] [ERROR] Retrying in 1 second.
[2020-09-24 16:37:09 +0000] [174092] [ERROR] Connection in use: ('127.0.0.1', 8000)
[2020-09-24 16:37:09 +0000] [174092] [ERROR] Retrying in 1 second.
[2020-09-24 16:37:10 +0000] [174092] [ERROR] Can't connect to ('127.0.0.1', 8000)

Its my understanding that there is already a gunicorn process running at port 8000, I have allowed access to port 8000, but I may have run a process with gunicorn before it was allowed.

I ran

sudo ss -plunt

and saw that there were four gunicorn pids for port 8000. I tried to run

pkill gunicorn

kill -9 pid#

to stop gunicorn or stop each pid on port 8000 but it did not work as when I ran these different gunicorn pid would replace the killed ones or they changed I am no exactly sure.

If anyone has encountered something like this or has any ideas how to solve this issue, that would be greatly appreciated. Or if you
think rebuilding is the best option which I am considering, let me know and tips to avoid running into this problem again. Thanks.

3 Replies

@rstorf25 --

You write:

Its my understanding that there is already a gunicorn process running at port 8000

To be pedantic, whatever is bound to localhost, port 8000 doesn't necessarily have to be a gunicorn process (although it most likely is). Any process bound to localhost, port 8000 will cause gunicorn to throw the same error.

That being said…

You need to find out what is restarting gunicorn automatically on app failure (your kills are considered app failures):

  • It could be systemd…the Linux system service daemon or
  • gunicorn may have a monitor process to automatically restart processes on failure.

I don't know which this is but the symptoms you describe certainly fit this diagnosis…

-- sw

I have the same issue. I used the Linode Flask image, ssh into the server, copied my Flask app over (which works locally), and after minor set up it says run gunicorn, but I get the same errors

Connection in use: ('127.0.0.1', 8000)

This is from a fresh set up, and using the Linode instructions:
https://www.linode.com/marketplace/apps/linode/flask/
https://www.linode.com/docs/guides/flask-and-gunicorn-on-ubuntu/

Thanks

I also am having this issue. I have been working on this for days and still cannot get this to work properly.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct