@@ -24,6 +24,7 @@ import { type MongoClient, type MongoClientOptions } from '../mongo_client';
24
24
import { type Filter , type WithId } from '../mongo_types' ;
25
25
import { type CreateCollectionOptions } from '../operations/create_collection' ;
26
26
import { type DeleteResult } from '../operations/delete' ;
27
+ import { CSOTTimeoutContext } from '../timeout' ;
27
28
import { MongoDBCollectionNamespace } from '../utils' ;
28
29
import * as cryptoCallbacks from './crypto_callbacks' ;
29
30
import {
@@ -276,7 +277,16 @@ export class ClientEncryption {
276
277
socketOptions : autoSelectSocketOptions ( this . _client . options )
277
278
} ) ;
278
279
279
- const { v : dataKeys } = deserialize ( await stateMachine . execute ( this , context ) ) ;
280
+ const timeoutContext : CSOTTimeoutContext | undefined =
281
+ typeof this . _timeoutMS === 'number'
282
+ ? ( CSOTTimeoutContext . create ( {
283
+ serverSelectionTimeoutMS : this . _client . s . options . serverSelectionTimeoutMS ,
284
+ waitQueueTimeoutMS : this . _client . s . options . waitQueueTimeoutMS ,
285
+ timeoutMS : this . _timeoutMS
286
+ } ) as CSOTTimeoutContext )
287
+ : undefined ;
288
+
289
+ const { v : dataKeys } = deserialize ( await stateMachine . execute ( this , context , timeoutContext ) ) ;
280
290
if ( dataKeys . length === 0 ) {
281
291
return { } ;
282
292
}
@@ -307,7 +317,7 @@ export class ClientEncryption {
307
317
. collection < DataKey > ( collectionName )
308
318
. bulkWrite ( replacements , {
309
319
writeConcern : { w : 'majority' } ,
310
- timeoutMS : this . _timeoutMS
320
+ timeoutMS : timeoutContext ?. remainingTimeMS
311
321
} ) ;
312
322
313
323
return { bulkWriteResult : result } ;
0 commit comments