gorilla/sessions

[question] How to check for session expiration in absence of a request?

MichaelHipp opened this issue · 7 comments

When a request is received, the session is checked for expiration. Good.

But if I kick off a long-running process based on that request, how do I check for expiration of the session during the running of that process? Is there some way the long-running process can periodically check if he session is still good? Note that the initial expiration time can be extended indefinitely if the session is being Save()-ed when other requests arrive for that session.

Thanks.

Use case: A request comes in (via a session) that is upgraded to a websocket connection. It starts a goroutine that sends quasi real-time data to the client (browser). It needs to run for as long as the user is looking at the browser. But if the user goes home for the weekend and doesn't close the browser I'd like the websocket to be terminated when the session expires. I don't want to trust the client to do this, so I need a way to force it closed from the server.

So, in the for{} loop that is the essence of the goroutine, I'd like to have a simple check to see if the session is still good.

Does this make any sense? Am I missing something obvious?

Thanks. Something like option 2 is where I'm headed because it does need to keep up with refreshes. I'll prolly maintain that state somewhere independent of the connection routine. I'd like to keep the logic inside the connection as minimal as possible and just be something like session.IsGood().

You said: "the session expiry as a timestamp: now + MaxAge or the value of Expires". I don't see an Expires member on the Session struct, where is this found?

Thanks.

Unless I missed it, the sessions API doesn't directly expose the cookie anywhere. I was just hoping to avoid a lot of redundant calculating of expiration when it has already been done elsewhere.