Ruby on Rails Thursday, October 27, 2011

Hello,
getting and setting values in the Thread.current hash appears in the RoR code a bunch of times, including in active_record and active_support.
I keep getting conflicting information, however, on whether information stored in Thread.current is dependable.

In essence, this is my question:

Is the Thread.current hash guaranteed to be available and private throughout one and only one request-response cycle?

In other words, if I do something like:
Thread.current[:my_own_very_special_key] = 1
at the beginning of a response, can I count on all parts of my application, including models(*), to reliably access that value?

Provided I also do:
Thread.current[:my_own_very_special_key] = nil
just before the end of the response (say, in a controller's after_filter), am I guaranteed that the information is not leaked to other processes/threads/requests/browsers/users?

(OK, I have just given out my ignorance of webserver and webapp framework innards. Oh well...)

Thanks!
Giuseppe

(*) I know that accessing Thread.current from my models is frowned upon, but I would very much like to know if the practice is safe, albeit ugly.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DqpC9pQVgGQJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment