Search code examples
ruby-on-railsrubyherokutimeoutrack

Timeout not working on heroku for Rails application


I tried increasing timeout, I have app running in production and it's deployed on heroku. I have some requests which takes more than 30 seconds. And those requests are insertion in database. Due to requirements i can't move those insertions to background job. I increased timeout to 60 seconds and later i increased this to 80 seconds and it was working fine. But recently it stopped running no matter what i do it's not letting me increase timeout. This works perfectly fine on development environment but not on production. And gem i used is rack-timout

I used these options:

Rack::Timeout.timeout = 60  # seconds
Rack::Timeout.wait_timeout = 60
Rack::Timeout.wait_overtime = 60
Rack::Timeout.service_timeout = 60
Rack::Timeout.service_past_wait = true

Initially i was using only timeout option and it used to work fine. But later i tried adding more option hoping any of them will work.

Server Output:

    2018-09-17T08:00:32.163182+00:00 heroku[router]: at=error code=H12 desc="Request timeout"
method=POST path="/organizations/53/events" host=HOST_NAME 
request_id=abbd22bf-5298-4480-m027-aa00a52a0587 fwd="103.7.79.236" dyno=web.1
connect=1ms service=30135ms status=503 bytes=0 protocol=https

Any help would be appreciated. Thanks in advance.


Solution

  • An H12 is a timeout given by Heroku, not raised by your app. Heroku doesn't give you a way to increase that timeout.

    You should move this to be async anyway. One way could be to trigger a request which creates a "job" object with a status. Then, everything you need to do is performed on the background. Once the action is finished, you update the status value from "pending" to "success".

    The client can fetch the job to know the advancement of that async action.