Heroku H12 Request Timeout: why it happens and how to fix it

Heroku's router gives up on a request after 30 seconds and logs H12. How to find the slow request, the common causes, and how to move slow work out of the web process.

· 7 min read · By the Spot Downtime team

H12 is Heroku's code for a request that took too long. The Heroku router waits up to 30 seconds for your app to respond. If nothing comes back in that time, it closes the connection, logs H12 Request timeout and sends the visitor a 503 with Heroku's generic application error page. Your app may well keep working on the request after that, which is part of what makes H12 confusing.

What an H12 looks like in the logs

H12 shows up in the Heroku log stream, not in your application log. Tail it:

bash
heroku logs --tail --app your-app

# Only router lines (where H12 is logged)
heroku logs --tail --app your-app --source heroku --dyno router

A timed-out request looks like this:

text
at=error code=H12 desc="Request timeout" method=GET path="/reports/export" host=your-app.example.com
request_id=8b1f... fwd="203.0.113.7" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https

The useful fields are path (which endpoint), service=30000ms (the router waited the full 30 seconds) and dyno (which dyno was handling it). If the same path repeats, you have one slow endpoint. If many different paths time out at once, the whole dyno is stuck or overloaded.

The 30-second rule

Two timers matter. The router returns H12 when your app doesn't send the first byte within 30 seconds. Once your app has sent a byte, the router allows a rolling 55-second window of silence in either direction before it closes the connection. You can't raise the 30 seconds with a setting. Any request that needs more than that has to be redesigned, which is the real fix in most cases.

The dyno keeps working after the timeout

The router drops the connection but doesn't cancel your code. A slow request keeps using a worker, a database connection and memory after the visitor has already seen the error. Retrying users make it worse.

Find which kind of H12 you have

One slow endpoint

The log shows the same path every time. Typical causes: an unindexed database query on a table that grew, an export or report built in the request, a call to a third-party API with no timeout, or an N+1 query loop. Reproduce it locally with the production data volume, or time it from outside:

bash
curl -o /dev/null -s -w "connect=%{time_connect}s ttfb=%{time_starttransfer}s total=%{time_total}s\n" \
  https://your-app.example.com/reports/export

Every request times out after a deploy or restart

If the dyno is still booting, requests queue and time out. Heroku expects a web process to bind to $PORT within 60 seconds; if it doesn't, you see R10 Boot timeout instead. A heavy start-up (asset compilation at boot, a migration run in the web process, a slow cache warm-up) can sit just under that limit and still time out the first requests. Move that work to the release phase or the build.

All endpoints slow because the dyno is saturated

Each dyno handles a fixed number of requests at once. With one single-threaded worker, a single slow request blocks everything behind it. Check how many workers or threads your server is configured for, and whether the dyno is out of memory (look for R14 Memory quota exceeded in the same log).

bash
# Procfile: several workers and threads instead of one
web: gunicorn app:app --workers 3 --threads 2 --timeout 25
# Rails / Puma
web: bundle exec puma -C config/puma.rb

Scaling to more dynos helps when the problem is queueing, and does nothing for a single request that takes a minute:

bash
heroku ps --app your-app
heroku ps:scale web=2 --app your-app

Fixes that work

  1. Move slow work out of the request. Accept the request, queue a background job (Sidekiq, Celery, RQ, Bull), return 202 Accepted with a status URL, and let the client poll or get a notification. Exports, report generation, image processing and bulk imports belong here.
  2. Put timeouts on everything your code waits for. Database statements, HTTP calls to other services and locks all need a limit well under 30 seconds, so the app fails fast with a useful error instead of hanging into an H12.
  3. Set a server-side request timeout below 30 seconds. In Ruby, the rack-timeout gem does this: heroku config:set RACK_TIMEOUT_SERVICE_TIMEOUT=20. In gunicorn use --timeout 25. The worker then dies with a stack trace you can read, instead of silently running on after the router gave up.
  4. Fix the query. Run EXPLAIN ANALYZE on the slow query, add the missing index, paginate large result sets, and cache expensive results.
  5. Add capacity if you're queueing. More dynos, a bigger dyno type, or more workers per dyno.

H12 versus H13, H18 and H19

  • H12: the app didn't answer within 30 seconds.
  • H13: the app accepted the connection and closed it without sending a response, often after a crash.
  • H18: the connection was cut part-way through the response.
  • H19: the router couldn't connect to the dyno within its connect timeout.

If you see H12 plus H13 together, a worker is probably being killed mid-request, for example by the memory limit or a server timeout. The same pattern on other platforms is covered in Vercel function timeouts, Netlify function timeouts and 502, 503 and 504 errors.

Seeing it from outside

H12s often hit one endpoint while the home page stays fast, so a check on the front page won't see them. Check the slow path directly, and keep an eye on response time as well as status. The guide to tracking API response times shows how to spot an endpoint creeping toward the limit before it crosses it.

HTTP headers checkerRequest a URL from outside your network and see the status code and headers it returns.

With Spot Downtime you can add an API monitor for the endpoints that matter, expect a specific status and body, and get alerted when it starts returning 503. Because failures are confirmed from California, Amsterdam and Singapore before an alert goes out, one slow response from a single region doesn't page you.

Get new guides by email

Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading