How do you diagnose a 500 error on Heroku when there is no error message in the logs?
Asked Answered
S

3

35

I have a Rails app on Heroku that is serving 500 errors at random intervals. Web pages will display "Internal server error" in plain text, instead of the usual "We're sorry. Something went wrong." page. When I refresh the page, it works fine.

The logs don't show me an error message, just

» 14:20:34.107 2013-10-11 12:20:33.763690+00:00 heroku router - - at=info method=HEAD path=/ host=www.mydomain.com fwd="184.73.237.85/ec2-184-73-237-85.compute-1.amazonaws.com" dyno=web.1 connect=1ms service=63ms status=200 bytes=0
» 14:21:03.957 2013-10-11 12:21:03.561867+00:00 heroku router - - at=info method=GET path=/ host=www.mydomain.com fwd="50.112.95.211/ec2-50-112-95-211.us-west-2.compute.amazonaws.com" dyno=web.1 connect=0ms service=1ms status=500 bytes=21

Support has told me to look at request queuing in New Relic, but New Relic only shows a big red mark saying the server is down (even though the site works fine when refreshed).

With no error messages, I'm at a loss for how to diagnose this issue.

Stairway answered 16/10, 2013 at 18:18 Comment(8)
You can try Fiddler...Alas
did you try restarting the app? sometimes the error is during startup.Bulahbulawayo
@JCG could you explain how fiddler could be used in this case?Bulahbulawayo
No, I can't actually...but if it's a web app, and its returning a 500, you should be able to see the headers in fiddler.Alas
@phoet, I just tried restarting the app a few times and it doesn't seem to trigger the 500 error.Stairway
@JCG you could simply use curl -I for that?Bulahbulawayo
Just a possibility, its not a liability to show OP a tool that may help him/her.Alas
Tools like fiddler only help if the OP can reproduce the problem. I'm assuming that @Stairway is just working from the log files here.Codding
O
17

In Heroku, I diagnose errors with LogEntries -- its far easier than the Heroku logs to diagnose errors.

What I do is load up the app, and in the LogEntries panel, go to "Live (Beta)". This shows any errors which appear, and are generally very explanatory

Just something that might help

Oralla answered 19/10, 2013 at 9:51 Comment(7)
Thanks, Rich. The logs I pasted in the question are from LogEntries. All it says is that there is a 500, no error messages or anything else.Stairway
Are you using Webrick?Oralla
Hmmm okay - to get this working, is there any chance you could comment out the thin gem in your GemFile? This will put webrick up, and allow you to see the errors you're getting :) We could go into Chat if you need some more help?Oralla
Thin hides error messages? I didn't know that. I've put up Webrick as you suggested and the 500 errors seem to have stopped. I've been told not to use Webrick in production, so maybe the answer is to use Unicorn instead.Stairway
We use Unicorn - I can post live code if you need to know how to get it to run on Heroku?Oralla
I managed it by following these two articles: devcenter.heroku.com/articles/rails-unicorn blog.codeship.io/2012/05/06/unicorn-on-heroku.html Thank you!Stairway
Congratulations!! I hope it works well for you and if you have any further issues, please just post a comment!Oralla
C
39

Try adding the rails_12factor gem to get a more robust error log ( only if you're using Heroku ).

Make sure you rake db:migrate your database on Heroku with heroku run rake db:migrate

Cesaria answered 28/7, 2014 at 0:44 Comment(5)
I was getting a 500 error, like the original poster, no more information was given, even with LogEntries. After running 'heroku run rake db:migrate', the app is running without errors.Inquisitive
Thanks, rails_12factor helped me with my logs on heroku well!Cosecant
it's 2016 now and db:migrate still worked for me :) thanks alot dude :) heroku should returns some errors if user forgot those rake commands.Lagena
This is exactly what I needed.Voiture
Just want to +1 this guy. I was using a <%console%> on my index page. Thank god for this gem.Faldstool
O
17

In Heroku, I diagnose errors with LogEntries -- its far easier than the Heroku logs to diagnose errors.

What I do is load up the app, and in the LogEntries panel, go to "Live (Beta)". This shows any errors which appear, and are generally very explanatory

Just something that might help

Oralla answered 19/10, 2013 at 9:51 Comment(7)
Thanks, Rich. The logs I pasted in the question are from LogEntries. All it says is that there is a 500, no error messages or anything else.Stairway
Are you using Webrick?Oralla
Hmmm okay - to get this working, is there any chance you could comment out the thin gem in your GemFile? This will put webrick up, and allow you to see the errors you're getting :) We could go into Chat if you need some more help?Oralla
Thin hides error messages? I didn't know that. I've put up Webrick as you suggested and the 500 errors seem to have stopped. I've been told not to use Webrick in production, so maybe the answer is to use Unicorn instead.Stairway
We use Unicorn - I can post live code if you need to know how to get it to run on Heroku?Oralla
I managed it by following these two articles: devcenter.heroku.com/articles/rails-unicorn blog.codeship.io/2012/05/06/unicorn-on-heroku.html Thank you!Stairway
Congratulations!! I hope it works well for you and if you have any further issues, please just post a comment!Oralla
H
6

The solution that worked for me when deploying my Django apps to Heroku is to go into the production.py file and change the code DEBUG = FALSE to DEBUG = TRUE. In this way, you should be able to see the errors that Django displays. Be aware that once you have found the error and have done the corrections, this setting must be changed back to FALSE.

In case changing to TRUE shows the app to work but the error is not visible then check your forms.py file and make sure that your models do not have any inconsistency. In my previous cases, the forms.py file has been the culprit.

Habitant answered 20/5, 2019 at 4:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.