Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

threadsafe! in ActiveSupport::Cache::Store extends all instances of the class, and breaking all but the one it was called on

#844

When you call threadsafe! on an instance of ActiveSupport::Cache::Store it extends the class with the ThreadSafe module, thus effecting all future instances, not just the current instance.

I don't think this is the desired behavior, but either way it ends up breaking all future instances because the @mutex instance variable will be null for them.

Instead, I think the author meant to "extend" the instance of the class with the ThreadSafe module.

Here is a monkey patch that does this:

module ActiveSupport module Cache

class Store
  def threadsafe!
    @mutex = Mutex.new
    self.extend ThreadSafety
    self
  end
end

end end

It appears that edge rails assumes all caches (except memory cache) are thread safe by default and so this is no longer an issue.

Reported by Kris Rasmussen · August 16th, 2008 @ 01:40 AM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. josh
    josh
    • State changed from new to wontfix

    Yeah, the memory store is the only issue so we have SynchronizedMemoryStore now.

    November 16th, 2008 @ 06:59 PM

  2. Kris Rasmussen
    Kris Rasmussen

    Hi Josh,

    Thanks for getting back to me on this. You may have fixed this in one of the later commits, but the default memcached library did not appear to be thread-safe to me. I had to extend it with the ThreadSafety module to get things to work reliably.

    Thanks, Kris

    November 17th, 2008 @ 05:43 AM