Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Session validate interval #21

Merged
merged 2 commits into from

2 participants

@neonstalwart
Owner

improve the session validation logic so that it is called at intervals defined by settings.sessionTTL.

in general, it looks like the existing code has wrong logic if you were to supply options.expires but i didn't dig into that. it looks like, the setTimeout for session validation would use options.expires as a number that represents an interval of time whereas if you were to follow the logic of the code that creates sessions via session = exports.forceSession(request, options.expires);, forceSession is going to treat that value as an absolute time representing when the session expires.

neonstalwart added some commits
@neonstalwart neonstalwart call sessionModel.validate at intervals ec409b0
@neonstalwart neonstalwart improve the session reaping logic.
 * allow validate to return a promise before calling again
 * change sign of timeout length so that it makes sense
c49943f
@kriszyp kriszyp merged commit c69d321 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 6, 2012
  1. @neonstalwart
  2. @neonstalwart

    improve the session reaping logic.

    neonstalwart authored
     * allow validate to return a promise before calling again
     * change sign of timeout length so that it makes sense
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 3 deletions.
  1. +9 −3 jsgi/session.js
View
12 jsgi/session.js
@@ -20,9 +20,15 @@ exports.Session = function(options, nextApp){
if (!options.expires) options.expires = -(settings.sessionTTL || 300);
// start the reaper
// TODO: get a timer for narwhal
- if (typeof exports.getSessionModel().validate === 'function' && typeof setTimeout !== "undefined") setTimeout(function(){
- exports.getSessionModel().validate();
- }, options.expires*1000);
+ function validate() {
+ // allow for this to occur asynchronously
+ when(exports.getSessionModel().validate(), function () {
+ setTimeout(validate, options.expires * -1000);
+ });
+ }
+ if (typeof exports.getSessionModel().validate === 'function' && typeof setTimeout !== "undefined") {
+ validate();
+ }
//
return function(request){
var session;
Something went wrong with that request. Please try again.