finds.dev

steveklabnik/request_store

Per-request global storage for Rack.

View on GitHubHomepage ↗

★ 1,499RubyMITupdated May 2024

// the take

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.

We read the README, the directory tree and a key source file in July 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
1,499
Forks
90
Language
Ruby
License
MIT
Last commit
1 May 2024

// nearby

If request_store isn't quite it.

All repos →