Skip to content

Add after filters in adapters to clear Authlogic::Session::Base.controller? #335

Closed
tiegz opened this Issue Nov 5, 2012 · 1 comment

1 participant

@tiegz
Collaborator
tiegz commented Nov 5, 2012

I'm experiencing a strange error in Rails 3.2 where the thread-local controller variable is different than the current request's controller. Having a hard time tracking it down, but we're using Unicorn (forked processes) and virtually have no threading in our app, so I'm having a hard time figuring it out.

The place where this occurs is when we override append_info_to_payload in ApplicationController (which is used in the action_controller instrumentation). We just append information to the instrumentation payload that references the current user, via Authlogic. Every once in a while, an error will be raised in this overriden method that indicates the Authlogic controller isn't the same as the current one.

My question is: wouldn't it be a good idea to use an after_filter (in Rails adapter, for example) to unset Authlogic::Session::Base.controller after the request to ensure that the var doesn't stick around?

@tiegz
Collaborator
tiegz commented Nov 6, 2012

Aha! I figured it out. The rails authenticity token filter is set before activate_authlogic:

[:verify_authenticity_token, :activate_authlogic, ... ]

When the :verify_authenticity_token fails, the controller var is never set in activate_authlogic, so our append_info_to_payload call is referring to the previous request's controller instead. Seems like there could still be some way to prevent this from happening, albeit an edge case.

@tiegz tiegz referenced this issue in drapergem/draper Dec 16, 2012
Closed

Use of Thread.current and ViewContext #390

@steveklabnik steveklabnik added a commit to steveklabnik/authlogic that referenced this issue Dec 17, 2012
@steveklabnik steveklabnik Integrate request_store to solve threading issues.
Fixes #335.

See also drapergem/draper#390
fa9625d
@steveklabnik steveklabnik added a commit to steveklabnik/authlogic that referenced this issue Mar 2, 2014
@steveklabnik steveklabnik Integrate request_store to solve threading issues.
Fixes #335.

See also drapergem/draper#390
9fd44b9
@binarylogic binarylogic closed this in #340 Mar 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.