@@ -25,7 +25,7 @@ import {
2525import type { Topology } from '../sdam/topology' ;
2626import type { ClientSession } from '../sessions' ;
2727import { TimeoutContext } from '../timeout' ;
28- import { squashError , supportsRetryableWrites } from '../utils' ;
28+ import { supportsRetryableWrites } from '../utils' ;
2929import { AbstractOperation , Aspect } from './operation' ;
3030
3131const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES . IllegalOperation ;
@@ -87,12 +87,6 @@ export async function executeOperation<
8787 ) ;
8888 }
8989
90- timeoutContext ??= TimeoutContext . create ( {
91- serverSelectionTimeoutMS : client . s . options . serverSelectionTimeoutMS ,
92- waitQueueTimeoutMS : client . s . options . waitQueueTimeoutMS ,
93- timeoutMS : operation . options . timeoutMS
94- } ) ;
95-
9690 const readPreference = operation . readPreference ?? ReadPreference . primary ;
9791 const inTransaction = ! ! session ?. inTransaction ( ) ;
9892
@@ -112,12 +106,18 @@ export async function executeOperation<
112106 session . unpin ( ) ;
113107 }
114108
109+ timeoutContext ??= TimeoutContext . create ( {
110+ serverSelectionTimeoutMS : client . s . options . serverSelectionTimeoutMS ,
111+ waitQueueTimeoutMS : client . s . options . waitQueueTimeoutMS ,
112+ timeoutMS : operation . options . timeoutMS
113+ } ) ;
114+
115115 try {
116116 return await tryOperation ( operation , {
117117 topology,
118+ timeoutContext,
118119 session,
119- readPreference,
120- timeoutContext
120+ readPreference
121121 } ) ;
122122 } finally {
123123 if ( session ?. owner != null && session . owner === owner ) {
@@ -156,6 +156,7 @@ type RetryOptions = {
156156 session : ClientSession | undefined ;
157157 readPreference : ReadPreference ;
158158 topology : Topology ;
159+ timeoutContext : TimeoutContext ;
159160} ;
160161
161162/**
@@ -179,7 +180,10 @@ type RetryOptions = {
179180async function tryOperation <
180181 T extends AbstractOperation < TResult > ,
181182 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 > {
183187 let selector : ReadPreference | ServerSelector ;
184188
185189 if ( operation . hasAspect ( Aspect . MUST_SELECT_SAME_SERVER ) ) {
@@ -197,7 +201,8 @@ async function tryOperation<
197201
198202 let server = await topology . selectServer ( selector , {
199203 session,
200- operationName : operation . commandName
204+ operationName : operation . commandName ,
205+ timeoutContext
201206 } ) ;
202207
203208 const hasReadAspect = operation . hasAspect ( Aspect . READ_OPERATION ) ;
0 commit comments