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