Skip to content

Commit 9307a80

Browse files
committed
clarify branching timeout behaviour
1 parent ecdd66d commit 9307a80

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: src/cmap/connection_pool.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
2929
import type { Server } from '../sdam/server';
3030
import { Timeout, TimeoutError } from '../timeout';
31-
import { type Callback, List, makeCounter, promiseWithResolvers } from '../utils';
31+
import { type Callback, csotMin, List, makeCounter, promiseWithResolvers } from '../utils';
3232
import { connect } from './connect';
3333
import { Connection, type ConnectionEvents, type ConnectionOptions } from './connection';
3434
import {
@@ -370,7 +370,9 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
370370
if (options?.timeout) {
371371
// CSOT enabled
372372
// Determine if we're using the timeout passed in or a new timeout
373-
if (options.timeout.duration === 0 || serverSelectionTimeoutMS < options.timeout.duration) {
373+
if (
374+
csotMin(options.timeout.duration, serverSelectionTimeoutMS) === serverSelectionTimeoutMS
375+
) {
374376
timeout = Timeout.expires(serverSelectionTimeoutMS - options.timeout.timeElapsed);
375377
} else {
376378
timeout = options.timeout;

Diff for: src/sdam/topology.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { Timeout, TimeoutError } from '../timeout';
3838
import type { Transaction } from '../transactions';
3939
import {
4040
type Callback,
41-
csotMin,
4241
type EventEmitterWithState,
4342
HostAddress,
4443
List,
@@ -569,7 +568,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
569568
if (options.timeout) {
570569
// CSOT Enabled
571570
timeout =
572-
csotMin(options.timeout.remainingTime, serverSelectionTimeoutMS) ===
571+
Math.min(options.timeout.remainingTime, serverSelectionTimeoutMS) ===
573572
serverSelectionTimeoutMS
574573
? Timeout.expires(serverSelectionTimeoutMS)
575574
: options.timeout;

0 commit comments

Comments
 (0)