finds.dev← search

// the find

steveklabnik/request_store

★ 1,499 · Ruby · MIT · updated May 2024

Per-request global storage for Rack.

A Rack middleware that gives you per-request global storage by clearing Thread.current between requests. Exists because threaded servers (Puma, Thin) reuse threads across requests, so naive Thread.current usage leaks state. Drop-in replacement pattern for any Rails or Rack app that already has Thread.current scattered through it.

Middleware approach is the right fix — clears storage in an ensure block so it survives exceptions. Railtie auto-installs the middleware so Rails apps need zero configuration. The companion request_store-sidekiq gem handles the background job case, which most alternatives ignore. Tiny surface area — the whole implementation is basically one file, easy to audit.

Still backed by Thread.current under the hood, which breaks with Fiber-based concurrency (Falcon server, async-ruby) — you get the same stale-value bugs this gem claims to solve. No fiber-local variant is provided or documented. Last meaningful commit was years ago; the 2024 push is likely CI config only. Also, if you're reaching for this, it's often a sign that something upstream should be passed explicitly rather than stored globally — the gem makes the bad pattern slightly less bad rather than steering you away from it.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →