[dancer-users] Session expiration cleanup

Maxwell Carey mcarey at ucar.edu
Wed Feb 25 19:25:30 GMT 2015

On Wed, Feb 25, 2015 at 10:48 AM, Warren Young <wyml at etr-usa.com> wrote:

> After 1 minute of closing the tab that created the session, an ls in the
> sessions directory shows old session *.yml files still sitting there.  Why
> aren’t these disappearing?

Dancer doesn't poll the filesystem to make sure sessions are still valid;
in fact, it can't, because it doesn't have an event loop and simply
responds to requests as they come in. Unless you send another request after
closing your tab, Dancer has no idea the session has expired.

Here's what happens when you access your app again after closing the tab:
your browser will see that your cookie has expired and will not send it
with the request. Dancer sees the request doesn't have a cookie with a
valid session ID, so it creates a new session and sends a new cookie back
to your browser. Dancer has no way to know that you previously had a
session that is now expired; it just sees a request with no cookie.

So it can't do any cleanup of old session files; you have to use cron or
something similar as Hugues mentioned.

> Second, I’ve got a pool of TCP connections to a back-end server, one per
> active session.  When the session is logged out normally, I can find the
> corresponding connection and close it, too.  But, if a session times out
> because it’s abandoned, my connection object never gets closed.  (I’ve put
> a log message in its DESTROY method, and it never occurs.)
> Is there a way to get Dancer to notify my code when it expires a session,
> so I can add some app-specific cleanup code?

Again, Dancer won't know the session is expired unless the user sends
another request. You'll have to set up something external to Dancer to
clean up your old TCP connections and run it periodically.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150225/65a1a762/attachment.html>

More information about the dancer-users mailing list