Heroku H12 Request Timeout Error when serving precompiled assets - heroku

I am running a rails application on Heroku. I've been getting H12 Request Timeout Errors every few hours as such:
heroku/router: at=error code=H12 desc="Request timeout" method=GET path="/assets/application-c280172e4ef44cbe29d1fc72c6dfcd00.js" host=www.justvacay.com request_id=8e570b7c-0470-47b7-9f3b-41c1158b448d fwd="66.249.79.111" dyno=web.1 connect=4ms service=30005ms status=503 bytes=0
This started happening after I installed unicorn-worker-killer.
Does anyone know how to fix this?

Heroku doesn't process HTTP requests for over 30seconds, so if you are trying to host an application that does a heavy duty task (for instance, access a working API or something else that takes a long time) it is best to create worker dynos that can do the heavy coding in the background.
Here are the steps to do this:
https://devcenter.heroku.com/articles/background-jobs-queueing
Another (potential) solution would be to go into the application that is taking a long time and create sessions within every function to avoid having heroku time running out. Here is an example on how to do this:
https://help.heroku.com/AXOSFIXN/why-am-i-getting-h12-request-timeout-errors-in-nodejs
This is not 100% guaranteed to work though.
Hope that this is helpful and good luck!

Related

Why doesn't my socket.io project on Heroku sleep?

It's a Node.js app serving a React app. I'm using free dynos so the app should sleep after not receiving any request, but it seems to be always on. I checked the billing on Heroku and it's consuming a significant amount of hours.
I would be fine waiting for the app to load up, but it won't sleep. Perhaps it has something to do with socket.io constantly pinging the server while no client is connected?
I only find topics on how to prevent sleeping, totally opposite of my intention. I also have another socket.io app on Heroku, but that one does sleep like expected.
Edit: The app logs tell that there are two socket connections made at the same time every 30 minutes, my app seems to be pinged by a pinger. How to stop unknown pinger?
My Heroku app was actually being pinged by a pinger. I freed the app from the pinger by changing the app name. Isn't it bad that anyone can add an app to a pinger and the publisher has to change the app name?

Heroku - Video won't load - H27 Client Request Interrupted

I have a video that is about 2 minutes long and 6.32MB in size. When I run a local server (using Python), the video loads just fine. However, when I try opening it on my website (hosted on Heroku), the video does not load.
This is the associated Heroku log:
sock=client
at=warning code=H27 desc="Client Request Interrupted"
method=GET path="/video.mp4" host=somewhere.com
dyno=web.1
connect=0ms service=26ms
status=499
bytes=
protocol=http
This StackOverflow answer states,
HTTP 499 in Nginx means that the client closed the connection before
the server answered the request. In my experience is usually caused by
client side timeout.
Heroku's description of the 'H27 - Client Request Interrupted' error is,
The client socket was closed either in the middle of the request or
before a response could be returned. For example, the client closed
their browser session before the request was able to complete.
What does this mean in terms of Heroku? What can I do so that my video loads?
The solution seems to be to host the video elsewhere =/
From this page,
There are two approaches to processing and storing file uploads from a
Heroku app to S3: direct and pass-through.
Direct upload
This is the preferred approach if you’re working with
file uploads bigger than 4MB. The idea is to skip the hop to your
dyno, making a direct connection from the end user browser to S3.

Is there a way to wake up the application when a user sends a message and it's idle on heroku?

I'm have a bot running on heroku within a free tier, and I'm looking for a way to wake the application when a message is received from the user in Slack.
I have a web worker in my Procfile:
web: npm start
I also setup a webserver and botkit:
var app = express();
var port = process.env.PORT || 3000;
app.listen(port, function (err) {
if (err) throw err;
console.log('Bot up!');
});
var controller = Botkit.slackbot({
debug: false
});
var bot = controller.spawn({
token: botConfig.SLACK_BOT_KEY
}).startRTM();
The bot goes up as normal, and goes idle after 30~ minutes of inactivity
2016-09-27T18:55:18.013318+00:00 app[web.1]: info: ** API CALL: https://slack.com/api/rtm.start
2016-09-27T18:55:18.027341+00:00 app[web.1]: Bot up!
2016-09-27T18:55:18.253156+00:00 app[web.1]: notice: ** BOT ID: bot ...attempting to connect to RTM!
2016-09-27T18:55:18.298822+00:00 app[web.1]: notice: RTM websocket opened
2016-09-27T18:55:18.346493+00:00 heroku[web.1]: State changed from starting to up
2016-09-27T19:25:42.535535+00:00 heroku[web.1]: Idling
2016-09-27T19:25:42.536182+00:00 heroku[web.1]: State changed from up to down
2016-09-27T19:25:46.877746+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-09-27T19:25:48.014988+00:00 heroku[web.1]: Process exited with status 143
Now, if I send a message to the bot in slack, it won't respond anymore and the application won't wake up unless I send a request to the webserver.
I don't want to prevent the bot from idling as it would consume my dyno hours, is there a way I can wake up the app when a user sends a message to the bot through slack?
Unfortunately, using RTM API, the RTM connection needs to be opened to receive a message. It seems like a tautology, but if the dyno is sleeping, the RTM connection is closed, and no message is seen by the server.
Your solution can be to switch to the Events API (either entirely, or just to enable waking-up your app. However, it you have both the RTM API and the Events API used in your app, make sure you don't react twice to the same message). The callback from the message event will wake up your app.
There will be a significant lag for the response to the first message, though. If that's not acceptable, then you could always pay 7$ / months :-p

Frequent 504 Gateway Time-out on appharbor

Deployed an asp.net mvc 4 app on appharbor with very low traffic. Each time the application is accessed after deployment of after a few minutes of inactivity, I get a 504 gateway time out error from nginx. Very annoying, what can I do to work around the error?
EDIT:
support ticket on appharbor's support site
The HTTP 504 is returned because the application doesn't respond within the request timeout. Application startup can take a little while, so sometimes a 504 may be returned on the initial request.
Applications on the free plan idle out after 20 minutes of inactivity. You can upgrade to one of the paid plans as they don't idle out after a period of inactivity.
We (AppHarbor) are working on decreasing the time it takes for applications to start up, which will mitigate the issue further. Note that the default request timeout was very recently increased to 120 seconds, so if you continue to experience this you're very welcome to open a ticket and let us know the application name so we can take a closer look.

Brief application error during/post deployment to Heroku

When we are deploying new code to Heroku we are often finding the first request (or couple) to hit get an application error back. After that everything runs fine.
They appear to be request timeouts:
2012-06-19T21:54:42+00:00 heroku[router]: Error H12 (Request timeout) -> GET www.mydomain.com/ dyno=web.2 queue= wait= service=30000ms status=503 bytes=0
We are using 'unicorn' with 3 processes if that has any possible connection (yes I should probably just run a test myself, but since it's intermittent and hard to pin down I'm hoping others have seen this.). Perhaps increasing the unicorn timeout value will help avoid this but I'm wondering if there is a way to deploy that doesn't result in such large delayed responses after deployment for the first few clients.
Indeed there is such a way to get deploy that may avoid this problem. You can use the Heroku preboot labs feature.
Also check out this Dev Center article on dealing with H12 request timeouts.

Resources