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

Commit ac68e76

Browse files
committed
fix(server-session-pool): ensure the queue is LIFO
NODE-1088
1 parent 3968a39 commit ac68e76

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/sessions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ServerSessionPool {
140140
}
141141

142142
if (!session.hasTimedOut(sessionTimeoutMinutes)) {
143-
this.sessions.push(session);
143+
this.sessions.unshift(session);
144144
}
145145
}
146146
}

test/tests/unit/sessions_tests.js

+20
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,25 @@ describe('Sessions', function() {
169169
done();
170170
}
171171
});
172+
173+
it('should maintain a LIFO queue of sessions', {
174+
metadata: { requires: { topology: 'single' } },
175+
test: function(done) {
176+
const pool = new ServerSessionPool(test.client);
177+
178+
const sessionA = new ServerSession();
179+
const sessionB = new ServerSession();
180+
181+
pool.release(sessionA);
182+
pool.release(sessionB);
183+
184+
const sessionC = pool.acquire();
185+
const sessionD = pool.acquire();
186+
187+
expect(sessionC.id).to.eql(sessionB.id);
188+
expect(sessionD.id).to.eql(sessionA.id);
189+
done();
190+
}
191+
});
172192
});
173193
});

0 commit comments

Comments
 (0)