@@ -25,7 +25,7 @@ import {
25
25
import type { Topology } from '../sdam/topology' ;
26
26
import type { ClientSession } from '../sessions' ;
27
27
import { TimeoutContext } from '../timeout' ;
28
- import { squashError , supportsRetryableWrites } from '../utils' ;
28
+ import { supportsRetryableWrites } from '../utils' ;
29
29
import { AbstractOperation , Aspect } from './operation' ;
30
30
31
31
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES . IllegalOperation ;
@@ -88,12 +88,6 @@ export async function executeOperation<
88
88
) ;
89
89
}
90
90
91
- timeoutContext ??= TimeoutContext . create ( {
92
- serverSelectionTimeoutMS : client . s . options . serverSelectionTimeoutMS ,
93
- waitQueueTimeoutMS : client . s . options . waitQueueTimeoutMS ,
94
- timeoutMS : operation . options . timeoutMS
95
- } ) ;
96
-
97
91
const readPreference = operation . readPreference ?? ReadPreference . primary ;
98
92
const inTransaction = ! ! session ?. inTransaction ( ) ;
99
93
@@ -113,12 +107,18 @@ export async function executeOperation<
113
107
session . unpin ( ) ;
114
108
}
115
109
110
+ timeoutContext ??= TimeoutContext . create ( {
111
+ serverSelectionTimeoutMS : client . s . options . serverSelectionTimeoutMS ,
112
+ waitQueueTimeoutMS : client . s . options . waitQueueTimeoutMS ,
113
+ timeoutMS : operation . options . timeoutMS
114
+ } ) ;
115
+
116
116
try {
117
117
return await tryOperation ( operation , {
118
118
topology,
119
+ timeoutContext,
119
120
session,
120
- readPreference,
121
- timeoutContext
121
+ readPreference
122
122
} ) ;
123
123
} finally {
124
124
if ( session ?. owner != null && session . owner === owner ) {
@@ -157,6 +157,7 @@ type RetryOptions = {
157
157
session : ClientSession | undefined ;
158
158
readPreference : ReadPreference ;
159
159
topology : Topology ;
160
+ timeoutContext : TimeoutContext ;
160
161
} ;
161
162
162
163
/**
@@ -180,7 +181,10 @@ type RetryOptions = {
180
181
async function tryOperation <
181
182
T extends AbstractOperation < TResult > ,
182
183
TResult = ResultTypeFromOperation < T >
183
- > ( operation : T , { topology, session, readPreference } : RetryOptions ) : Promise < TResult > {
184
+ > (
185
+ operation : T ,
186
+ { topology, timeoutContext, session, readPreference } : RetryOptions
187
+ ) : Promise < TResult > {
184
188
let selector : ReadPreference | ServerSelector ;
185
189
186
190
if ( operation . hasAspect ( Aspect . MUST_SELECT_SAME_SERVER ) ) {
@@ -198,7 +202,8 @@ async function tryOperation<
198
202
199
203
let server = await topology . selectServer ( selector , {
200
204
session,
201
- operationName : operation . commandName
205
+ operationName : operation . commandName ,
206
+ timeoutContext
202
207
} ) ;
203
208
204
209
const hasReadAspect = operation . hasAspect ( Aspect . READ_OPERATION ) ;
0 commit comments