0

I am trying to deploy a Flask app on Heroku. Whenever I make a request to the server, my Heroku log gives me an H12 timeout error without any other information:

2018-06-25T21:25:58.755278+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=live-event-market-api.herokuapp.com request_id=a1638941-9d56-4364-b9e6-ba46b6fa875f fwd="73.186.40.243" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https

After a great deal of searching, I realized that the problem had to do with connecting to my database: when I comment out the code which connects to the database, requests to the app on Heroku work fine.

#create all db tables
@app.before_first_request
def create_tables():
    from database import init_db
    init_db()
    #^^^get rid of all this, and the app works fine on Heroku

After looking at this, I decided that I needed to SSL certify heroku. I have gone through the steps, and it seems like I should be connecting successfully. However, it's very hard to accurately debug this without any kind of error messages (like this one reported by another SO poster).

Does anybody have any idea how I can get a better stack trace from Heroku here? I can't know what the error is unless my code tells me--all I know is that, for some reason, my Heroku dyno can't connect to my Amazon RDS MySQL database within 30 seconds.

Note also that my app works perfectly on my local machine. It is only when I push it to Heroku that I start having troubles.

Edit: Note too how I'm trying to connect to the DB:

engine = create_engine(os.environ['DB_URI'],connect_args={'ssl':{'ca':'amazon-rds-ca-cert.pem','cert':'amazon-rds-ca-cert.pem'}})
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
    from models import UserModel, RevokedTokenModel, PromoterModel, EventInfo, Event
    Base.metadata.create_all(bind=engine)

Where DB_URI is a config variable with a valid AWS instance's url.

Gelineau
  • 2,031
  • 4
  • 20
  • 30
Toby Weed
  • 594
  • 2
  • 7
  • 20
  • is your db open to your heroku instance or vice versa? – Skam Jun 25 '18 at 22:08
  • @Skam I don't know, that's the problem. Is there a way to find out besides trying to connect? Because when I try to connect nothing happens, the server just times out. – Toby Weed Jun 25 '18 at 22:13
  • did you see https://stackoverflow.com/questions/35247347/point-heroku-application-to-aws-rds-database?noredirect=1&lq=1 – Skam Jun 25 '18 at 22:14
  • @Skam yes. I tried following those directions (and others). They did not do anything--but if I made any small mistake, I would not know it (because I am not getting any error message) – Toby Weed Jun 25 '18 at 22:20
  • @TobyWeed it's definitely not useful when errors are abstracted into a simple Timeout error! Off the top of my head: try checking the RDS logs to see if your request is hitting RDS or not. You can try looking at the MySQL General Query log or CloudWatch for any errors or confirmation of connections. That would be an important diagnostic detail. – Andy G Sep 06 '18 at 13:58

0 Answers0