Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default request time out on Heroku?

Tags:

My app is built on Rails and my production server is on Heroku.

My application is mostly used for file upload and file processing and it takes more than 50 seconds for the request to process. As per the Heroku configuration my request does not respond in time and it sends me to the application error page due to request timeout.

How can I change the request timeout configuration on Heroku?

Please help me out to make application working.

like image 432
jayesh Avatar asked Feb 13 '14 09:02

jayesh


People also ask

What is request timeout?

The HyperText Transfer Protocol (HTTP) 408 Request Timeout response status code means that the server would like to shut down this unused connection. It is sent on an idle connection by some servers, even without any previous request by the client.

How do I fix Heroku H12 error?

A restart cancels long-running requests. Restarting can resolve H12 issues because freshly-booted dynos receive requests without interference from long-running requests. Using the Heroku CLI, run heroku ps:restart web to restart all web dynos. or, using the Heroku Dashboard, click More, then Restart all dynos.

What happens when request timeout?

Request timeout is sent by a server indicating that the server wants to close the connection (note that sometimes server may close the connection without sending a message).


2 Answers

This is not possible according to Heroku's documentation

The timeout value is not configurable. If your server requires longer than 30 seconds to complete a given request, we recommend moving that work to a background task or worker to periodically ping your server to see if the processing request has been finished. This pattern frees your web processes up to do more work, and decreases overall application response times.

like image 117
Santhosh Avatar answered Oct 06 '22 17:10

Santhosh


As already mentioned, you need to process it in the background because you cannot change the timeout enforced by Heroku. This is actually a good thing, because it will allow for a much better design where the web application is responsive and it can also scale much better.

What this means is that you need to use something like for instance delayed job and you can read about it on Heroku here.

The flow of things would be something like this:

  1. upload the document within the hard limit (timeout) enforced by Heroku.
  2. schedule a background job to process document and return 200 OK to the browser.
  3. browser waits for completion by e.g. background AJAX polling of a flag to see when background job is ready.
  4. delayed job picks up scheduled work and upon completion it sets the flag to indicate the background job is done.
  5. Browser can now inform the user that it is done (up to your application to know what fits).

This is an idea how this can be done. You have a few different ways you can do it and delayed job is just one you can choose from.

like image 45
murrekatt Avatar answered Oct 06 '22 18:10

murrekatt