0

I have developed a web app. After the user makes a POST, some processing starts which takes some time. When the function ends, a response is served to the client. Meanwhile, when the POST happens, the page is refreshed on the client side, a new div is shown. So the client sees a new page.

But i uploaded my app to Heroku, and while my app works fine on my machine, Heroku throws an H12 timeout error after 30 seconds of the server not sending a response, to answer the client POST request.

In my application this is unnecessary and kills my app.

Is there a way to turn off request timeouts in Heroku?

After all, when the client makes the POST, hiw view changes. It's like he received a new reponse.

2

The issue you're facing is Heroku's 30 second router timeout (not the 60-second boot timeout). 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.

You can read more here: https://devcenter.heroku.com/articles/background-jobs-queueing

  • Thanks! When my long running job is finished, it serves a text file to the user. It sets the headers and it is served from the memory of the server to the client as a text file. If i do what you said, then how will the client get notified that the job is ready, so he visits a route to download the text file? I will have already served a response to the client (to comply with the 30 second rule). So how can i notify him that the job is done? – user1584421 Sep 25 '18 at 17:21
  • Your client can poll for changes. Create a database table with a “processed” (Boolean) field which defaults to fakes. The client polls. Once your background job is complete, it can update the record to processed = true. The next time the client polls, your web server can return the text file. This blog post talked about this pattern (and a few other options) pillow.codes/… – Jon McCartie Sep 25 '18 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.