Skip to content

Commit 6e4a9c6

Browse files
committed
fix: LB leaks connection on client close with expired session error
1 parent 2a65d43 commit 6e4a9c6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/sessions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,11 @@ export function maybeClearPinnedConnection(
533533
const servers = Array.from(topology.s.servers.values());
534534
const loadBalancer = servers[0];
535535

536-
if (options?.error == null || options?.force) {
536+
if (
537+
options?.error == null ||
538+
options?.error?.name === 'MongoExpiredSessionError' ||
539+
options?.force
540+
) {
537541
loadBalancer.pool.checkIn(conn);
538542
session[kPinnedConnection] = undefined;
539543
conn.emit(

0 commit comments

Comments
 (0)