Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(server-session-pool): don't add expired sessions to the pool
Browse files Browse the repository at this point in the history
NODE-1088
  • Loading branch information
mbroadst committed Oct 6, 2017
1 parent 933ab7f commit 8f48b89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ServerSession {
(((Date.now() - this.lastUse) % 86400000) % 3600000) / 60000
);

return idleTimeMinutes > sessionTimeoutMinutes;
return idleTimeMinutes > sessionTimeoutMinutes - 1;
}
}

Expand Down Expand Up @@ -135,7 +135,9 @@ class ServerSessionPool {
}
}

this.sessions.push(session);
if (!session.hasTimedOut(sessionTimeoutMinutes)) {
this.sessions.push(session);
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/tests/unit/sessions_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,19 @@ describe('Sessions', function() {
done();
}
});

it('should not reintroduce a soon-to-expire session to the pool on release', {
metadata: { requires: { topology: 'single' } },

test: function(done) {
const session = new ServerSession();
session.lastUse = new Date(Date.now() - 9.5 * 60 * 1000).getTime(); // add 9.5min

const pool = new ServerSessionPool(test.client);
pool.release(session);
expect(pool.sessions).to.have.length(0);
done();
}
});
});
});
3 changes: 2 additions & 1 deletion test/tests/unit/single/sessions_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ describe('Sessions (Single)', function() {
sentIsMaster = true;
request.reply(
assign({}, mock.DEFAULT_ISMASTER, {
maxWireVersion: 6
maxWireVersion: 6,
logicalSessionTimeoutMinutes: 10
})
);
});
Expand Down

0 comments on commit 8f48b89

Please sign in to comment.