Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/sdam/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ export class TopologyClosedEvent {
export class ServerHeartbeatStartedEvent {
/** The connection id for the command */
connectionId: string;
/** Is true when using the streaming protocol. */
awaited: boolean;

/** @internal */
constructor(connectionId: string) {
constructor(connectionId: string, awaited: boolean) {
this.connectionId = connectionId;
this.awaited = awaited;
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/sdam/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ function resetMonitorState(monitor: Monitor) {

function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
let start = now();
monitor.emit(Server.SERVER_HEARTBEAT_STARTED, new ServerHeartbeatStartedEvent(monitor.address));
const topologyVersion = monitor[kServer].description.topologyVersion;
const isAwaitable = topologyVersion != null;
monitor.emit(
Server.SERVER_HEARTBEAT_STARTED,
new ServerHeartbeatStartedEvent(monitor.address, isAwaitable && topologyVersion != null)
);

function failureHandler(err: Error) {
monitor[kConnection]?.destroy({ force: true });
Expand Down Expand Up @@ -237,8 +242,6 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
const { serverApi, helloOk } = connection;
const connectTimeoutMS = monitor.options.connectTimeoutMS;
const maxAwaitTimeMS = monitor.options.heartbeatFrequencyMS;
const topologyVersion = monitor[kServer].description.topologyVersion;
const isAwaitable = topologyVersion != null;

const cmd = {
[serverApi?.version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND]: 1,
Expand Down Expand Up @@ -288,7 +291,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
if (isAwaitable && hello.topologyVersion) {
monitor.emit(
Server.SERVER_HEARTBEAT_STARTED,
new ServerHeartbeatStartedEvent(monitor.address)
new ServerHeartbeatStartedEvent(monitor.address, true)
);
start = now();
} else {
Expand Down