@@ -2,7 +2,7 @@ import { promises as fs } from 'fs';
22import type { TcpNetConnectOpts } from 'net' ;
33import type { ConnectionOptions as TLSConnectionOptions , TLSSocketOptions } from 'tls' ;
44
5- import { type ServerCommandOptions , type TimeoutContext } from '.' ;
5+ import { type ServerCommandOptions , type TimeoutContext , TopologyType } from '.' ;
66import { type BSONSerializeOptions , type Document , resolveBSONOptions } from './bson' ;
77import { ChangeStream , type ChangeStreamDocument , type ChangeStreamOptions } from './change_stream' ;
88import type { AutoEncrypter , AutoEncryptionOptions } from './client-side-encryption/auto_encrypter' ;
@@ -795,11 +795,11 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
795795 return ;
796796 }
797797
798- const topologyDescription = this . topology . description ;
799- const areSessionsSupported = topologyDescription . logicalSessionTimeoutMinutes != null ;
800-
801- if ( areSessionsSupported ) {
802- await endSessions ( this ) ;
798+ const {
799+ description : { type , logicalSessionTimeoutMinutes }
800+ } = this . topology ;
801+ if ( type === TopologyType . LoadBalanced || logicalSessionTimeoutMinutes != null ) {
802+ await endSessions ( this , this . topology ) ;
803803 }
804804
805805 // clear out references to old topology
@@ -813,7 +813,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
813813 await encrypter . close ( this ) ;
814814 }
815815
816- async function endSessions ( client : MongoClient ) {
816+ async function endSessions (
817+ client : MongoClient ,
818+ { description : topologyDescription } : Topology
819+ ) {
817820 // If we would attempt to select a server and get nothing back we short circuit
818821 // to avoid the server selection timeout.
819822 const selector = readPreferenceServerSelector ( ReadPreference . primaryPreferred ) ;
0 commit comments