steveklabnik / request_store

Per-request global storage for Rack.
https://github.com/steveklabnik/request_store
MIT License
1.48k stars 87 forks source link

How come this is thread safe? #64

Closed tareksamni closed 5 years ago

tareksamni commented 5 years ago

I've reviewed the simple and straight forward implementation of this gem but I could not understand: How come this is a thread safe store?

Uses Rack::BodyProxy, adapted from Rack::Lock's usage of the same pattern. This is totally good/true except that you do not use any Mutexs as in Rack::Lock. so how do you manage conccurent / multi-threaded usage of this Middleware?

is there any magical usage of the request_store_active because you declare, set and clear it but I can't understand where is the value of having this in the thread store!

Could @steveklabnik give more details/illustration in the README.md?

steveklabnik commented 5 years ago

I wrote this gem three years ago. IIRC, because I'm using Thread.current, it's thread local storage, which means that the store is per-thread, so you can't access it from different threads.

Maybe there's a bug here, if you can demonstrate something, please le tme know!