Skip to content

Commit 0ba5e40

Browse files
committed
fix(NODE-5840): heartbeat duration includes socket creation
1 parent 5908b37 commit 0ba5e40

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/sdam/monitor.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { clearTimeout, setTimeout } from 'timers';
22

33
import { type Document, Long } from '../bson';
4-
import { connect } from '../cmap/connect';
4+
import { connect, makeConnection, makeSocket, performInitialHandshake } from '../cmap/connect';
55
import type { Connection, ConnectionOptions } from '../cmap/connection';
66
import { getFAASEnv } from '../cmap/handshake/client_metadata';
77
import { LEGACY_HELLO_COMMAND } from '../constants';
@@ -235,7 +235,7 @@ function useStreamingProtocol(monitor: Monitor, topologyVersion: TopologyVersion
235235
}
236236

237237
function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
238-
let start = now();
238+
let start: number;
239239
let awaited: boolean;
240240
const topologyVersion = monitor[kServer].description.topologyVersion;
241241
const isAwaitable = useStreamingProtocol(monitor, topologyVersion);
@@ -335,6 +335,8 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
335335
);
336336
}
337337

338+
start = now();
339+
338340
if (isAwaitable) {
339341
awaited = true;
340342
return connection.exhaustCommand(ns('admin.$cmd'), cmd, options, (error, hello) => {
@@ -352,7 +354,13 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
352354
}
353355

354356
// 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(
356364
connection => {
357365
if (isInCloseState(monitor)) {
358366
connection.destroy({ force: true });

0 commit comments

Comments
 (0)