Heroku server - Rails View errors but the code runs fine - ruby-on-rails

I have a snippet of code that takes quite a while to run - About two minutes. Locally, when this code is initiated through a button in my view, the page just appears to be loading until the two minutes is up.
When I deployed this to heroku, the code was erroring out. I changed my Unicorn timeout time to allow for the code to finish, and now when looking at my logs the code is completing just fine.
However, I am presented with this error in my heroku app's view:
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
How can I get the same behavior I have locally on my heroku app? I would prefer that the page just continue to appear as if it were loading until the code is complete.
EDIT
I'm seeing this in my logs:
2014-01-14T17:11:49.388634+00:00 heroku[router]: at=error code=H12 desc="Request timeout"
method=POST path=/fluidsurveys/test_send_file host=glacial-spire-1431.herokuapp.com
fwd="66.195.31.22" dyno=web.1 connect=6ms service=30090ms status=503 bytes=0

Related

Heroku H10 error but web dynos are not crashing

A few hours ago we starting seeing a bunch of H10 errors in our logs and on our Heroku dashboard. Heroku says that H10 errors are due to web dyno crashes. Read more here. The strange part is that our 2 web dynos are running completely fine and not crashing at all.
Here's an example of what I'm seeing in the logs:
2021-08-12T20:50:35.934439+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/v1/graphql" host=api.rize.io request_id=abcd-ace1-44e8-99f5-03d38d8eaa5a fwd="1.1.1.1" dyno= connect= service= status=503 bytes= protocol=https
When I search for that request ID, abcd-ace1-44e8-99f5-03d38d8eaa5a in this example, in the logs (as Heroku recommends), nothing shows up except the router error listed above.
I've restarted all the dynos and the issue persists.
Anyone have any idea what could be going on and how we can fix this?
I don't know if this is an answer for other people but we discovered that our DNS settings were not updated to match the changes documented here: https://devcenter.heroku.com/changelog-items/2151
We also needed to re-establish managed SSL certificates for our custom domains.
Our setup has some complications related to proxies we have in front of Heroku though and the fact that of the three custom domains we have configured on the app, only two of them had been migrated, which complicated the debugging of this situation.
This was due to a Heroku incident. Here is the incident status:
https://status.heroku.com/incidents/2311
I asked Heroku support and he rolled back the infrastructure upgrade (https://devcenter.heroku.com/changelog-items/2151) for our site.
After that, we don't have H10 errors.
Dunno if it helps, but I've cloned my app to a new one (letting all env vars on the old ones) and directed everything to the new Heroku app.
It seems to be working just good enough while waiting for the problem to be solved by the Heroku team. No H10 errors but some H31, nothing is broken anymore though.

Exception catch for Heroku "Connection closed without response"

I am using heroku to run my application and set the timeout = 12s (using racktimeout), using unicorn, sometimes I am getting the H13 issue
2010-10-06T21:51:37-07:00 heroku[router]: at=error code=H13 desc="Connection closed without response"
method=GET path="/" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=12610ms service=15882ms
status=503 bytes=0
So this breaks in between the code execution, can we handle this in the exception anyway? Am I doing anything wrong here?
Set the timeout to 30 seconds. And examine if the problem will recur. This should help.
The documentation says:
When a Unicorn web server is configured with a timeout shorter than 30s and a request has not been processed by a worker before the timeout happens.
In this case, Unicorn closes the connection before any data is written, resulting in an H13.
https://devcenter.heroku.com/articles/error-codes#h13-connection-closed-without-response

How to get Heroku Logs to show relevant information about error

My Rails application on Heroku shows me this error screen:
When I run heroku logs from my terminal it only shows:
2016-03-03T22:30:11.442364+00:00 heroku[router]: at=info method=POST path="/posts" host=www.mysite.com request_id=9b490b19-ca40-45b9-b09f-16a5b064d174 fwd="23.248.115.183" dyno=web.1 connect=2ms service=2271ms status=500 bytes=1754
How can I get the logs to show some actual information about the error (as they would in the development environment).
This error appeared after and update involving a mailer and sendgrid smtp.
If you have complete control over the Heroku setup then I can recommend hooking up the Rollbar Add-on to keep track of all your errors and their tracebacks. There is a free tier so you can try it first.
https://elements.heroku.com/addons/rollbar
You can tail the logs with:
heroku logs -t
If you have multiple apps from that directory:
heroku logs -t --app the-name-of-your-app
Those will give you tailings logs.
Here's Heroku's article on logging (with anchor to --tail):
https://devcenter.heroku.com/articles/logging#real-time-tail

heroku router - - at=error code=H12 - Site going down for 30s every day or two

Heroku Rails site going down every day or two for 30 seconds max, alerts sent by uptime-robot.
Have tried to run some basic load testing, and doesn't seem take the site down when under solid traffic. Not running any expensive queries on the homepage.
Error logs look like the below. Running rails on hobby dev.
Not getting any errors through New Relic. Running Puma 'puma', '~> 2.15.3'.
Have this set on rack timeout initailizer: Rack::Timeout.timeout = 15
Dec 07 20:14:46 sleepy-wave-3748 heroku/router: at=error code=H12 desc="Request timeout" method=GET path="/" host=mySiteUrlHere request_id=274ed877-2edb-43f2-8b77-c7a82f17109a fwd="69.162.124.231,108.162.221.131" dyno=web.1 connect=1ms service=30007ms status=503 bytes=0
Dec 07 20:35:46 sleepy-wave-3748 heroku/router: at=error code=H12 desc="Request timeout" method=HEAD path="/" host=mySiteUrlHere request_id=1b43b249-f089-4a4a-a42b-b2886d607fa8 fwd="69.162.124.231,108.162.221.131" dyno=web.1 connect=0ms service=30003ms status=503 bytes=0
Any Suggestions ?
Heroku will typically disconnect after 30 seconds and return a 503 error. It appears that your service may be responding successfully but after 30 seconds have passed. This could explain why you are not seeing application errors but are seeing Heroku errors.
EDIT: I think I may have misread your question. Heroku goes through a cycling process on some of its dynos. During this time, there may be a possibility for it to appear that your application has gone down. If you are using free dynos, they require a period of downtime (per rolling 24hr period)
I think I have solved it. I found a pull request in the Puma github account relating to this issue and noticed the fix had been included in a later version of Puma. After upgrading my Puma version, the problem has stopped happening. Hopefully this can help someone else out.
Note, I upgraded to Puma 2.15.3 from 2.11.2 .

Rails app crashes on Heroku but runs fine locally -> "State changed from starting to crashed"

repo at: git#github.com:assafshomer/sample_app.git
This app is my learning app based on Michael Hartl's excellent railstutorial.
App runs smoothly in development and test suite is all green
When deploying to Heroku I get the following error immediatly: "Application Error. An error occurred in the application and your page could not be served"
The problem started after upgrading to Rails4 (but I know the problem is not Rails4 itself because, e.g. git://github.com/railstutorial/sample_app_rails_4.git deploys fine to Heroku)
I know you are going to ask "did you migrate the db on Heroku?". I did. I even ran pg:reset and then again rake db:migrate on Heroku just in case. They seemed to have run ok.
Heroku logs don't give any info either (at least, nothing I can see as useful)
2013-05-25T22:11:26.070468+00:00 heroku[web.1]: Process exited with
status 0
2013-05-25T22:11:26.083572+00:00 heroku[web.1]: State changed from
starting to crashed
2013-05-25T22:13:09.372294+00:00 heroku[run.4121]: State changed from up
to complete
2013-05-25T22:13:09.357146+00:00 heroku[run.4121]: Process exited with
status 1
2013-05-25T22:13:50.829887+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path=/ host=devsampleapp.herokuapp.com
fwd="93.172.16.63" dyno= connect= service= status=503 bytes=
also the rails console doesn't come up:
2013-05-26T06:41:34.942569+00:00 heroku[api]: Starting process with command `bin/rails console` by assafshomer#gmail.com
2013-05-26T06:41:38.312107+00:00 heroku[run.5325]: Awaiting client
2013-05-26T06:41:38.339816+00:00 heroku[run.5325]: Starting process with command `bin/rails console`
2013-05-26T06:41:39.112396+00:00 heroku[run.5325]: Client connection closed. Sending SIGHUP to all processes
2013-05-26T06:41:40.329832+00:00 heroku[run.5325]: Process exited with status 0
2013-05-26T06:41:40.357047+00:00 heroku[run.5325]: State changed from starting to complete
I submitted a support ticket with Heroku, but that will only be attended to earliest Tuesday, and I'm itching to get this "upgrade to rails4" working already, so, any help in resolving this mystery will be much appreciated.
obviously, the best way to reproduce is to clone the repo and deploy to heroku :)
Thanks!!
Assaf Shomer (assafshomer at gmail)
In rails4 several files (bin/rails, bin/rake and bin/bundle) responsible for the startup phase have been newly added or moved from different locations (e.g. script/rails).
Seems that they are missing in your application. Strange thing indeed that it works on your local machine but not on heroku - but well I tried and added them. It seems to work.
You can create them by simply running rake rails:update:bin.

Resources