6

I have a Flask app that runs fine on local, but when I push to Heroku I get the error message:

* Running on http://127.0.0.1:5000/
[INFO] Starting gunicorn 18.0
[ERROR] Connection in use: ('0.0.0.0', 8163)

I tried the solution in this question, where gunicorn and werkzeug were fighting with each other, but adding a __name__ == "__main__" block to my master application file (run.py) didn't solve my error.

This SO post suggested making sure my processes were all cleaned up. I did that but it still didn't work, so I actually deleted my entire heroku app and repushed and it still gives the same error.

My run.py file looks like:

#!pl_env/bin/python
from app import app

if __name__ == "__main__":
  app.run(debug=True, port=33507)

# [33507 is the Flask port on Heroku]

And my Procfile is: web: gunicorn run:app

The __init__.py file in app is:

from flask import Flask
import os
from flask.ext.login import LoginManager

app = Flask(__name__)
app.config.from_object('config')

lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'

from app import views

Views has the meaty logic of the app in it, but I don't think there's anything in there that would mess with gunicorn. Here's the views.py imports just in case:

from flask import Flask, render_template, flash, redirect
from flask.ext.login import login_required, login_user
from app import app, lm
from forms import LoginForm

I am definitely at a loss as to where to look now to figure out this connection error. Any thoughts on why it seems to think I'm already using 0.0.0.0?

Thank you

Monica

EDIT: I ran the app locally using foreman start and it worked cleanly in 0.0.0.0:5000, so I think I'm having a Heroku problem

EDIT2: I intentionally broke my view flow -- made an internal infinite reference -- and pushed it to see what would happen. I got the expected error logs, undid it, and pushed the rollback, and now it's working. I have absolutely no idea why that should work, except maybe that breaking it in an expected way flushed my gunicorn connections. If anyone has any explanations for this mystery, I would love them.

Community
  • 1
  • 1
quaintm
  • 677
  • 1
  • 7
  • 18
  • Your app should not be available on `5000` since you are nowhere specifying that port that I can see. (You specify `33507` in `run.py` and gunicorn's error message suggests it is trying to bind to `8163`) - are you creating another Flask app in `views.py` and running it unguarded perhaps? – Sean Vieira Dec 06 '13 at 17:00
  • That's an interesting question--in my successful run, gunicorn is binding to `18629`, and foreman locally is looking at `5000`, and no one is looking at `33507`. I don't *think* I'm creating a new app in `views.py`, I think I'm importing the existing `__init__.py`, but here is a gist of `views.py`: https://gist.github.com/quaintm/7828814 – quaintm Dec 06 '13 at 17:30
  • 1
    Ah - 8163 may have been a pid (process id) - somehow the old gunicorn process was not being torn down when you did an update, resulting in errors. – Sean Vieira Dec 06 '13 at 17:49

1 Answers1

0
app.run(host='0.0.0.0') 

might do the trick as explained here

Community
  • 1
  • 1
CESCO
  • 7,305
  • 8
  • 51
  • 83