@@ -209,15 +209,25 @@ function resetMonitorState(monitor: Monitor) {
209209
210210function checkServer ( monitor : Monitor , callback : Callback < Document | null > ) {
211211 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+ ) ;
213218
214219 function failureHandler ( err : Error ) {
215220 monitor [ kConnection ] ?. destroy ( { force : true } ) ;
216221 monitor [ kConnection ] = undefined ;
217222
218223 monitor . emit (
219224 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+ )
221231 ) ;
222232
223233 const error = ! ( err instanceof MongoError )
@@ -237,8 +247,6 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
237247 const { serverApi, helloOk } = connection ;
238248 const connectTimeoutMS = monitor . options . connectTimeoutMS ;
239249 const maxAwaitTimeMS = monitor . options . heartbeatFrequencyMS ;
240- const topologyVersion = monitor [ kServer ] . description . topologyVersion ;
241- const isAwaitable = topologyVersion != null ;
242250
243251 const cmd = {
244252 [ serverApi ?. version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND ] : 1 ,
@@ -278,17 +286,18 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
278286 const duration =
279287 isAwaitable && rttPinger ? rttPinger . roundTripTime : calculateDurationInMs ( start ) ;
280288
289+ const awaited = isAwaitable && hello . topologyVersion != null ;
281290 monitor . emit (
282291 Server . SERVER_HEARTBEAT_SUCCEEDED ,
283- new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello )
292+ new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , awaited )
284293 ) ;
285294
286295 // if we are using the streaming protocol then we immediately issue another `started`
287296 // event, otherwise the "check" is complete and return to the main monitor loop
288- if ( isAwaitable && hello . topologyVersion ) {
297+ if ( awaited ) {
289298 monitor . emit (
290299 Server . SERVER_HEARTBEAT_STARTED ,
291- new ServerHeartbeatStartedEvent ( monitor . address )
300+ new ServerHeartbeatStartedEvent ( monitor . address , true )
292301 ) ;
293302 start = now ( ) ;
294303 } else {
@@ -324,7 +333,12 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
324333 monitor [ kConnection ] = conn ;
325334 monitor . emit (
326335 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+ )
328342 ) ;
329343
330344 callback ( undefined , conn . hello ) ;
0 commit comments