1
1
import { clearTimeout , setTimeout } from 'timers' ;
2
2
3
3
import { type Document , Long } from '../bson' ;
4
- import { connect } from '../cmap/connect' ;
4
+ import { connect , makeConnection , makeSocket , performInitialHandshake } from '../cmap/connect' ;
5
5
import type { Connection , ConnectionOptions } from '../cmap/connection' ;
6
6
import { getFAASEnv } from '../cmap/handshake/client_metadata' ;
7
7
import { LEGACY_HELLO_COMMAND } from '../constants' ;
@@ -235,7 +235,7 @@ function useStreamingProtocol(monitor: Monitor, topologyVersion: TopologyVersion
235
235
}
236
236
237
237
function checkServer ( monitor : Monitor , callback : Callback < Document | null > ) {
238
- let start = now ( ) ;
238
+ let start : number ;
239
239
let awaited : boolean ;
240
240
const topologyVersion = monitor [ kServer ] . description . topologyVersion ;
241
241
const isAwaitable = useStreamingProtocol ( monitor , topologyVersion ) ;
@@ -335,6 +335,8 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
335
335
) ;
336
336
}
337
337
338
+ start = now ( ) ;
339
+
338
340
if ( isAwaitable ) {
339
341
awaited = true ;
340
342
return connection . exhaustCommand ( ns ( 'admin.$cmd' ) , cmd , options , ( error , hello ) => {
@@ -352,7 +354,13 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
352
354
}
353
355
354
356
// connecting does an implicit `hello`
355
- connect ( monitor . connectOptions ) . then (
357
+ ( async ( ) => {
358
+ const socket = await makeSocket ( monitor . connectOptions ) ;
359
+ const connection = makeConnection ( monitor . connectOptions , socket ) ;
360
+ start = now ( ) ;
361
+ await performInitialHandshake ( connection , monitor . connectOptions ) ;
362
+ return connection ;
363
+ } ) ( ) . then (
356
364
connection => {
357
365
if ( isInCloseState ( monitor ) ) {
358
366
connection . destroy ( { force : true } ) ;
0 commit comments