# Rails: Rack::Timeout::RequestTimeoutException: Request ran for 15001ms, exceeding the 15000ms timeout (Heroku H12)

**Code:** `Rack::Timeout::RequestTimeoutException` · **Category:** Ruby / Rails · **Seen on:** Ruby

A request took longer than `rack-timeout`'s limit (or Heroku's 30 s router timeout), so it was aborted.

## Meaning

Find slow code: N+1 queries, slow external APIs, big exports. Move heavy work to background jobs (Sidekiq/ActiveJob), add indexes, caches and timeouts on HTTP clients. Tune `RACK_TIMEOUT_SERVICE_TIMEOUT` only after fixing causes. Heroku H12 means the router gave up after 30 s.

## Common causes

- N+1 queries or missing DB indexes
- Slow third-party API without timeouts
- Long exports/reports in a request
- Cold boot/memory pressure
- Too few workers/threads causing queueing

## Quick fix

1. Profile with `rack-mini-profiler`/APM; fix N+1 (`includes`)
2. Use background jobs for long tasks
3. Set client timeouts (Faraday/Net::HTTP)

## Detailed fix by platform

### Rails

1. `config.middleware.insert_before Rack::Runtime, Rack::Timeout, service_timeout: 20`

## How to diagnose

1. **Cause** — DB/API/CPU?
2. **Queue** — Request queueing?
3. **Fix** — Background job?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/rack-timeout-requesttimeoutexception)
