express-sessions icon indicating copy to clipboard operation
express-sessions copied to clipboard

mongo session expiry is out by factor of 1000

Open steveliles opened this issue 11 years ago • 0 comments

Mongo session expiry uses a TTL index. The index is created by this code in index.js:

var schema = new mongoose.Schema({
    sid: { type: String, required: true, unique: true },
    data: { type: {} },
    lastAccess: { 
        type: Date, 
        index: { 
            expires: parseInt(options.expire) * 1000
        } 
    },
    expires: { type: Date, index: true }
});

The issue here is that expires is set to options.expire*1000, as if expecting to receive a value in seconds and convert it to milliseconds. However, if we look at the index that gets created:

{
"v" : 1,
"name" : "lastAccess_1",
"key" : {
    "lastAccess" : 1
},
"ns" : "mayqat.sessions",
"expireAfterSeconds" : 60000,
"background" : true,
"safe" : null
}

Notice that mongodb actually calls the value "expireAfterSeconds".

Easy fix: don't multiply by 1000 :)

I have forked and fixed, and could provide a pull request, though i've changed one other thing also (for issue 3).

steveliles avatar Apr 22 '14 15:04 steveliles