Home > front end >  Heroku - Dash: Port already in use
Heroku - Dash: Port already in use

Time:06-06

I wanted to deploy my plotly dashboard on Heroku, however upon running I keep getting information that the Port [PORT_NUMBER] is already in use. The port number is given by Heroku itself and changes everytime I restart the app. I tried setting up an app with a fixed port however it just stated that the given port is also 'in use by another program'. There are a few issues regarding something similar but they all pertain deploymend of node.js app and seemed to have been resolved by using a solution specific to node.js deployement.

Since I tried to locate the problem, I reduced my main module to minimal working example in app.py file:

from dash import Dash, html

app = Dash(__name__)
server = app.server
app.layout = html.Div("TESTING")
app.run_server(debug=False)

Procfile defined as follows:

web: gunicorn app:server

And here is the log from the running server I keep getting:

2022-06-05T15:38:23.696572 00:00 app[web.1]: * Serving Flask app 'app' (lazy loading)
2022-06-05T15:38:23.696693 00:00 app[web.1]: * Environment: production
2022-06-05T15:38:23.696830 00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2022-06-05T15:38:23.696863 00:00 app[web.1]: Use a production WSGI server instead.
2022-06-05T15:38:23.696883 00:00 app[web.1]: * Debug mode: off
2022-06-05T15:38:23.702649 00:00 app[web.1]: Address already in use
2022-06-05T15:38:23.702652 00:00 app[web.1]: Port 45013 is in use by another program. Either identify and stop that program, or start the server with a different port.
2022-06-05T15:38:23.702869 00:00 app[web.1]: [2022-06-05 15:38:23  0000] [489] [INFO] Worker exiting (pid: 489)
2022-06-05T15:38:23.850179 00:00 app[web.1]: [2022-06-05 15:38:23  0000] [491] [INFO] Booting worker with pid: 491
2022-06-05T15:38:24.280232 00:00 app[web.1]: Dash is running on http://127.0.0.1:45013/
2022-06-05T15:38:24.280241 00:00 app[web.1]:
2022-06-05T15:38:24.280618 00:00 app[web.1]: * Serving Flask app 'app' (lazy loading)
2022-06-05T15:38:24.284103 00:00 app[web.1]: * Environment: production
2022-06-05T15:38:24.284156 00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2022-06-05T15:38:24.284186 00:00 app[web.1]: Use a production WSGI server instead.
2022-06-05T15:38:24.284209 00:00 app[web.1]: * Debug mode: off
2022-06-05T15:38:24.295838 00:00 app[web.1]: Address already in use
2022-06-05T15:38:24.295891 00:00 app[web.1]: Port 45013 is in use by another program. Either identify and stop that program, or start the server with a different port.
2022-06-05T15:38:24.296221 00:00 app[web.1]: [2022-06-05 15:38:24  0000] [490] [INFO] Worker exiting (pid: 490)
2022-06-05T15:38:24.702612 00:00 app[web.1]: [2022-06-05 15:38:24  0000] [492] [INFO] Booting worker with pid: 492
2022-06-05T15:38:24.826989 00:00 app[web.1]: Dash is running on http://127.0.0.1:45013/
2022-06-05T15:38:24.826991 00:00 app[web.1]:
2022-06-05T15:38:24.827286 00:00 app[web.1]: * Serving Flask app 'app' (lazy loading)
2022-06-05T15:38:24.832077 00:00 app[web.1]: * Environment: production
2022-06-05T15:38:24.832127 00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2022-06-05T15:38:24.832158 00:00 app[web.1]: Use a production WSGI server instead.
2022-06-05T15:38:24.832182 00:00 app[web.1]: * Debug mode: off
2022-06-05T15:38:24.834227 00:00 app[web.1]: Address already in use
2022-06-05T15:38:24.834256 00:00 app[web.1]: Port 45013 is in use by another program. Either identify and stop that program, or start the server with a different port.
2022-06-05T15:38:24.834479 00:00 app[web.1]: [2022-06-05 15:38:24  0000] [491] [INFO] Worker exiting (pid: 491)
2022-06-05T15:38:25.150842 00:00 app[web.1]: [2022-06-05 15:38:25  0000] [493] [INFO] Booting worker with pid: 493

It just keeps starting up and failing due to busy port.

What am I doing wrong?

Edit

Redeploying app from scratch solved the issue.

CodePudding user response:

If the port is changing and the result keep being the same. There is following ways to try:

  1. Verify that you are not running several servers on one port. For example, in your running configuration you are starting your server directly AND also using gunicorn simultaneously.
  2. Try to redeploy the app from scratch. (Maybe it's some strange Heroku bug triggered on this specific deployment.)
  • Related