So I deploy an existing app using Passenger for the first time and hit this:
The only Google results had to do with components and how they could result in the sweeper's after filter getting called twice which would results in a nil controller variable the second time thru. But I wasn't using components.
Finally after adding a bit of logging to show me FULL stack traces each time cache_sweeper was called I found something interesting: application.rb was being loaded twice.
I use Exception Logger in this app so I have this small bit of code in my production environment:
That set's up authentication on the LoggedException controller so not just anyone can access it in production. The problem is line #2. We're requiring application.rb since we don't have it yet this early in the stack. But then Passenger is coming along a little later and requiring it again inside preload_application.
Thankfully Passenger is using require_dependency (which checks to see if the same dependency has already been loaded via require_dependency)... so if we used require_dependency also then we'd avoid this. A diff:
Problem solved. I'll be submitting a patch on github for this as well.
But is it really Passenger's fault?
Someone tried to make the argument that this has nothing to do with Passenger. I could argue it's not my require call that breaks anything but rather Passenger's later require_dependency call - but I won't do that.
My point of view is this: It worked before for years and when I moved to Passenger it broke. From where I'm standing it doesn't really matter who is to blame. Only that the app worked in a "traditional" Rails deployment (Mongrel) and did not work with Passenger.
Regardless of who's code is at fault I think this is the type of issue Passenger has to take some of the heat for. If someone comes out with a new car with the gas and brake pedals reversed I think one could make a strong argument that the car manufacturer shares some of the blame (if not most) for wrecks resulting from people hitting the wrong pedal. It's not a perfect analogy, but we don't live in a perfect world. :-)
This post is mostly intended to help others deal with similar problems they might have moving to Passenger - not just to cast stones at Passenger.