[Catalyst] Session::Store (::Memcached?) sharing/wrong user session data

Ric Johnson ric at xymmetrix.com
Wed May 18 13:31:01 GMT 2011


Hello!

I believe I've solved--or at least worked around--this problem. It is a Catalyst::View::HTML::Mason issue.

The issue is, that I am passing the context $c globally to Catalyst::View::HTML::Mason as suggested in the docs but while the static context/session based data seems to work (i.e. stash and flash), the $c->user functions appear to be pulling information from a memory block in the current web server, not from the session data proper.

[Unlike TT which has native support for calls to the context (c.<blah>), getting the context to HTML::Mason is a hack.]

The solution was to not trust the $c->user functions in the HTML::Mason View, but to access those functions in the Controller (in my case Root.pm after authentication) and put the users name, etc into $c->flash which passed it properly to the View.

Of course, this is what I should have been doing in a proper MVC design to begin with. Calling any function out of (the) context (pun intended) in a View is probably a gross violation of a View's proper place in nature.

tl;dr: NEVER do $c->user->get( <thing> ) in a Catalyst::View::HTML::Mason view. It doesn't work.

Here you go, Mr. Archiver! Save this to the interwebs to help the next guy!

Ric

-----Original Message-----
From: Ric Johnson 
Sent: Friday, May 13, 2011 6:00 PM
To: catalyst at lists.scsys.co.uk
Subject: [Catalyst] Session::Store (::Memcached?) sharing/wrong user session data

Hi,

I'm new to the list but I've searched the archives of the list and can't find anything even related to this question.

I am using Sessions with Memcached. My config:

Authentication
Authorization::Roles
Authorization::ACL 
Session
Session::State::Cookie
Session::Store::Memcached

Calls to $c->user->get( '<user db field name>' ) [in a Mason template using View::HTML::Mason] return values that are not the ones I should see.

For instance:

I login as 'ric', my $c->user->get( 'first_name' ) should return "Ric"

But I randomly get (depending on which Apache server instance I hit) a first_name associated with some other user's session. So I open 4 browsers and log in as 4 different users.

If I go back to ANY of the 4 browsers (FF, IE, Safari, Chrome) and refresh the page that prints $c->user->get( 'first_name' ) over and over and I get a random sampling of the 4 users logged in and even some empty strings. (Don't know if that's related.) It's clearly showing the info for the first user that logged in under that copy of the Apache web server session.

I've even called $c->user before $c->user->get() [as opposed to $c->user_exists] to be sure to pull user info back from the db--to no avail. 

[Guessing Starts Here]
It seems like when the $c->user data is retrieved, it gets stuck into the memory space of the webserver. Then it never reloads that info from disk or memcached.

I can't even say this is peculiar to ::Memcached because when I was using ::FastMmap, I was having to many other issues with the shared disk file and permissions so I abandoned it for Memcached.

So anything you could do to help would be very . . . helpful. -- King Arthur, Python

Thanks,
Ric


_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list