@@ -12,7 +12,7 @@ import { type Collection } from '../collection';
12
12
import { type FindCursor } from '../cursor/find_cursor' ;
13
13
import { type Db } from '../db' ;
14
14
import { getMongoDBClientEncryption } from '../deps' ;
15
- import { type MongoClient } from '../mongo_client' ;
15
+ import { type MongoClient , type MongoClientOptions } from '../mongo_client' ;
16
16
import { type Filter , type WithId } from '../mongo_types' ;
17
17
import { type CreateCollectionOptions } from '../operations/create_collection' ;
18
18
import { type DeleteResult } from '../operations/delete' ;
@@ -28,7 +28,11 @@ import {
28
28
type KMSProviders ,
29
29
refreshKMSCredentials
30
30
} from './providers/index' ;
31
- import { type CSFLEKMSTlsOptions , StateMachine } from './state_machine' ;
31
+ import {
32
+ type ClientEncryptionSocketOptions ,
33
+ type CSFLEKMSTlsOptions ,
34
+ StateMachine
35
+ } from './state_machine' ;
32
36
33
37
/**
34
38
* @public
@@ -199,7 +203,8 @@ export class ClientEncryption {
199
203
200
204
const stateMachine = new StateMachine ( {
201
205
proxyOptions : this . _proxyOptions ,
202
- tlsOptions : this . _tlsOptions
206
+ tlsOptions : this . _tlsOptions ,
207
+ socketOptions : autoSelectSocketOptions ( this . _client . options )
203
208
} ) ;
204
209
205
210
const dataKey = deserialize ( await stateMachine . execute ( this , context ) ) as DataKey ;
@@ -256,7 +261,8 @@ export class ClientEncryption {
256
261
const context = this . _mongoCrypt . makeRewrapManyDataKeyContext ( filterBson , keyEncryptionKeyBson ) ;
257
262
const stateMachine = new StateMachine ( {
258
263
proxyOptions : this . _proxyOptions ,
259
- tlsOptions : this . _tlsOptions
264
+ tlsOptions : this . _tlsOptions ,
265
+ socketOptions : autoSelectSocketOptions ( this . _client . options )
260
266
} ) ;
261
267
262
268
const { v : dataKeys } = deserialize ( await stateMachine . execute ( this , context ) ) ;
@@ -637,7 +643,8 @@ export class ClientEncryption {
637
643
638
644
const stateMachine = new StateMachine ( {
639
645
proxyOptions : this . _proxyOptions ,
640
- tlsOptions : this . _tlsOptions
646
+ tlsOptions : this . _tlsOptions ,
647
+ socketOptions : autoSelectSocketOptions ( this . _client . options )
641
648
} ) ;
642
649
643
650
const { v } = deserialize ( await stateMachine . execute ( this , context ) ) ;
@@ -715,7 +722,8 @@ export class ClientEncryption {
715
722
const valueBuffer = serialize ( { v : value } ) ;
716
723
const stateMachine = new StateMachine ( {
717
724
proxyOptions : this . _proxyOptions ,
718
- tlsOptions : this . _tlsOptions
725
+ tlsOptions : this . _tlsOptions ,
726
+ socketOptions : autoSelectSocketOptions ( this . _client . options )
719
727
} ) ;
720
728
const context = this . _mongoCrypt . makeExplicitEncryptionContext ( valueBuffer , contextOptions ) ;
721
729
@@ -957,3 +965,21 @@ export interface RangeOptions {
957
965
sparsity : Long ;
958
966
precision ?: number ;
959
967
}
968
+
969
+ /**
970
+ * Get the socket options from the client.
971
+ * @param baseOptions - The mongo client options.
972
+ * @returns ClientEncryptionSocketOptions
973
+ */
974
+ export function autoSelectSocketOptions (
975
+ baseOptions : MongoClientOptions
976
+ ) : ClientEncryptionSocketOptions {
977
+ const options : ClientEncryptionSocketOptions = { autoSelectFamily : true } ;
978
+ if ( 'autoSelectFamily' in baseOptions ) {
979
+ options . autoSelectFamily = baseOptions . autoSelectFamily ;
980
+ }
981
+ if ( 'autoSelectFamilyAttemptTimeout' in baseOptions ) {
982
+ options . autoSelectFamilyAttemptTimeout = baseOptions . autoSelectFamilyAttemptTimeout ;
983
+ }
984
+ return options ;
985
+ }
0 commit comments