Destroying liftSession from within a comet request gives NullPointerException

150 views
Skip to first unread message

Matt Feury

unread,
Aug 10, 2011, 3:31:08 PM8/10/11
to lif...@googlegroups.com
Greetings,

I'm attempting to force logout on a user. My flow is as such:

1. Comets get sent a BootUser message
2. The comet handler for this message calls UserSessions.logout and returns a reload command

However, in my logout method I'm attempting to destroy the liftSession (S.session) by calling destroySession. This seems to consistently result in a NullPointerException (at LiftSession.scala:711). 

Is there some issue with getting the request/session while in a comet? How can this session properly be destroyed?

thanks,
Matt

(I am on 2.3-M1)

Diego Medina

unread,
Aug 10, 2011, 10:07:32 PM8/10/11
to lif...@googlegroups.com
You are getting a NPE because a comet actor can be on several browser
windows belonging to different users/ sessions. How about using a
regular snippet to destroy the session and after that send a message
to your comet actor to refresh or update the page?


You can use something like this to send your comet a message from a snippet

for (sess <- S.session) sess.sendCometActorMessage(
"CometClassNameHere", Full("messageAsString"), cometNameIThink
)


Regards.

Diego

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

--
Diego Medina
Web Developer
(305) 788-4954
di...@fmpwizard.com
http://www.fmpwizard.com

Peter Brant

unread,
Aug 11, 2011, 7:15:46 AM8/11/11
to lif...@googlegroups.com
Actually comet actors are associated with a single session (and hence
a single user). They might be sending updates to several tabs or
windows though. On the other hand, they are independent of any given
request. I suspect it's the lack of an underlying request instance
that's causing the NPE (i.e. at some point
HttpServletRequest#getSession() is being called on a null
HttpServletRequest). We might be able to handle this more gracefully,
but I agree with Diego that your approach sounds more complicated than
it needs to be.

Pete

Antonio Salazar Cardozo

unread,
Aug 11, 2011, 3:54:51 PM8/11/11
to lif...@googlegroups.com
Yeah it's not actually possible to run it in a snippet, I'm afraid. What we're trying to do is put a user suspension/ban into effect. The state is saved to the database and then the user is `kicked'. The suspension/ban is executed by another user (a moderator), travels to an actor, and then the actor sends a message to the various comets telling them they've been kicked. The comet then logs its session out, which destroys the liftSession.

That's where we're getting the nullpointer. A new approach is forming in my mind at the moment, but it would still be awesome if this one could work for simplicity's sake.
Thanks,
Antonio

Peter Brant

unread,
Aug 11, 2011, 5:06:39 PM8/11/11
to lif...@googlegroups.com
I wonder if there are any issues with holding onto the HttpSession
object in the actor. I know the HttpServletRequest instance can only
be used during request processing, but I don't know if any similar
rules exist for HttpSession.

Pete

> --
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/liftweb/-/niA4NsH4p20J.

Diego Medina

unread,
Aug 11, 2011, 5:13:48 PM8/11/11
to lif...@googlegroups.com

Sent from my cell
Diego


On Aug 11, 2011 3:55 PM, "Antonio Salazar Cardozo" <savedf...@gmail.com> wrote:
>
> Yeah it's not actually possible to run it in a snippet, I'm afraid.

I haven't tried this yet but from your comet you can do a SetHtml (id, S.RunTemplate (name here))

And in that template you can have your snippet do the logout

I can expand later tonight when I have more time

Diego

What we're trying to do is put a user suspension/ban into effect. The state is saved to the database and then the user is `kicked'. The suspension/ban is executed by another user (a moderator), travels to an actor, and then the actor sends a message to the various comets telling them they've been kicked. The comet then logs its session out, which destroys the liftSession.
>
> That's where we're getting the nullpointer. A new approach is forming in my mind at the moment, but it would still be awesome if this one could work for simplicity's sake.
> Thanks,
> Antonio
>

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/liftweb/-/niA4NsH4p20J.

David Pollak

unread,
Aug 12, 2011, 7:56:21 PM8/12/11
to lif...@googlegroups.com
On Wed, Aug 10, 2011 at 12:31 PM, Matt Feury <matt...@gmail.com> wrote:
Greetings,

I'm attempting to force logout on a user. My flow is as such:

1. Comets get sent a BootUser message
2. The comet handler for this message calls UserSessions.logout and returns a reload command

However, in my logout method I'm attempting to destroy the liftSession (S.session) by calling destroySession. This seems to consistently result in a NullPointerException (at LiftSession.scala:711). 

The issue is that the Req instance that is used in CometActors is a mock Req instance that is not associated with a session.  It's a bug that Lift throws an NPE... please open a ticket at http://ticket.liftweb.net (you must be a watcher of the LiftWeb space on Assembla to open tickets.)
 

Is there some issue with getting the request/session while in a comet? How can this session properly be destroyed?

I'd suggest doing a partialUpdate(RedirectTo("/user_mgt/logout")) in your CometActor.  That will redirect all tabs that have the CometActor open to the logout page.  The logout page will destroy the session.

Does that help?
 

thanks,
Matt

(I am on 2.3-M1)

Please upgrade to Lift 2.3 or 2.4-M3.
 

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To view this discussion on the web visit https://groups.google.com/d/msg/liftweb/-/xOauoxgBzmUJ.

To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



--
Lift, the simply functional web framework http://liftweb.net

Tim Williams

unread,
Nov 20, 2011, 7:32:53 AM11/20/11
to lif...@googlegroups.com
I think this also causes an issue when unit testing with logged in users.

e.g. taking the assembla example and adding below line after the login call also results in a NPE from the destroySessions method.

User.logUserOut()

http://www.assembla.com/spaces/liftweb/wiki/Unit_Testing_Snippets_With_A_Logged_In_User

I'm trying to test whether User object is correctly tracking how many users are logged in, not sure if there is a different logout method I should be using.

Reply all
Reply to author
Forward
0 new messages