@@ -209,15 +209,25 @@ function resetMonitorState(monitor: Monitor) {
209
209
210
210
function checkServer ( monitor : Monitor , callback : Callback < Document | null > ) {
211
211
let start = now ( ) ;
212
- monitor . emit ( Server . SERVER_HEARTBEAT_STARTED , new ServerHeartbeatStartedEvent ( monitor . address ) ) ;
212
+ const topologyVersion = monitor [ kServer ] . description . topologyVersion ;
213
+ const isAwaitable = topologyVersion != null ;
214
+ monitor . emit (
215
+ Server . SERVER_HEARTBEAT_STARTED ,
216
+ new ServerHeartbeatStartedEvent ( monitor . address , isAwaitable )
217
+ ) ;
213
218
214
219
function failureHandler ( err : Error ) {
215
220
monitor [ kConnection ] ?. destroy ( { force : true } ) ;
216
221
monitor [ kConnection ] = undefined ;
217
222
218
223
monitor . emit (
219
224
Server . SERVER_HEARTBEAT_FAILED ,
220
- new ServerHeartbeatFailedEvent ( monitor . address , calculateDurationInMs ( start ) , err )
225
+ new ServerHeartbeatFailedEvent (
226
+ monitor . address ,
227
+ calculateDurationInMs ( start ) ,
228
+ err ,
229
+ isAwaitable
230
+ )
221
231
) ;
222
232
223
233
const error = ! ( err instanceof MongoError )
@@ -237,8 +247,6 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
237
247
const { serverApi, helloOk } = connection ;
238
248
const connectTimeoutMS = monitor . options . connectTimeoutMS ;
239
249
const maxAwaitTimeMS = monitor . options . heartbeatFrequencyMS ;
240
- const topologyVersion = monitor [ kServer ] . description . topologyVersion ;
241
- const isAwaitable = topologyVersion != null ;
242
250
243
251
const cmd = {
244
252
[ serverApi ?. version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND ] : 1 ,
@@ -278,17 +286,18 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
278
286
const duration =
279
287
isAwaitable && rttPinger ? rttPinger . roundTripTime : calculateDurationInMs ( start ) ;
280
288
289
+ const awaited = isAwaitable && hello . topologyVersion != null ;
281
290
monitor . emit (
282
291
Server . SERVER_HEARTBEAT_SUCCEEDED ,
283
- new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello )
292
+ new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , awaited )
284
293
) ;
285
294
286
295
// if we are using the streaming protocol then we immediately issue another `started`
287
296
// event, otherwise the "check" is complete and return to the main monitor loop
288
- if ( isAwaitable && hello . topologyVersion ) {
297
+ if ( awaited ) {
289
298
monitor . emit (
290
299
Server . SERVER_HEARTBEAT_STARTED ,
291
- new ServerHeartbeatStartedEvent ( monitor . address )
300
+ new ServerHeartbeatStartedEvent ( monitor . address , true )
292
301
) ;
293
302
start = now ( ) ;
294
303
} else {
@@ -324,7 +333,12 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
324
333
monitor [ kConnection ] = conn ;
325
334
monitor . emit (
326
335
Server . SERVER_HEARTBEAT_SUCCEEDED ,
327
- new ServerHeartbeatSucceededEvent ( monitor . address , calculateDurationInMs ( start ) , conn . hello )
336
+ new ServerHeartbeatSucceededEvent (
337
+ monitor . address ,
338
+ calculateDurationInMs ( start ) ,
339
+ conn . hello ,
340
+ false
341
+ )
328
342
) ;
329
343
330
344
callback ( undefined , conn . hello ) ;
0 commit comments