@@ -120,7 +120,6 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
120120 minHeartbeatFrequencyMS : options . minHeartbeatFrequencyMS ?? 500 ,
121121 serverMonitoringMode : options . serverMonitoringMode
122122 } ) ;
123- console . log ( getFAASEnv ( ) ) ;
124123 this . isRunningInFaasEnv = getFAASEnv ( ) != null ;
125124
126125 const cancellationToken = this [ kCancellationToken ] ;
@@ -241,15 +240,8 @@ function useStreamingProtocol(monitor: Monitor, topologyVersion: TopologyVersion
241240
242241function checkServer ( monitor : Monitor , callback : Callback < Document | null > ) {
243242 let start = now ( ) ;
244- const topologyVersion = monitor [ kServer ] . description . topologyVersion ;
245- console . log ( 'checkServer' , topologyVersion ) ;
246- const isAwaitable = useStreamingProtocol ( monitor , topologyVersion ) ;
247- monitor . emit (
248- Server . SERVER_HEARTBEAT_STARTED ,
249- new ServerHeartbeatStartedEvent ( monitor . address , isAwaitable )
250- ) ;
251-
252- function failureHandler ( err : Error ) {
243+
244+ function failureHandler ( err : Error , isAwaitable : boolean ) {
253245 monitor [ kConnection ] ?. destroy ( { force : true } ) ;
254246 monitor [ kConnection ] = undefined ;
255247
@@ -281,6 +273,13 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
281273 const connectTimeoutMS = monitor . options . connectTimeoutMS ;
282274 const maxAwaitTimeMS = monitor . options . heartbeatFrequencyMS ;
283275
276+ const topologyVersion = monitor [ kServer ] . description . topologyVersion ;
277+ const isAwaitable = useStreamingProtocol ( monitor , topologyVersion ) ;
278+ monitor . emit (
279+ Server . SERVER_HEARTBEAT_STARTED ,
280+ new ServerHeartbeatStartedEvent ( monitor . address , isAwaitable )
281+ ) ;
282+
284283 const cmd = {
285284 [ serverApi ?. version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND ] : 1 ,
286285 ...( isAwaitable && topologyVersion
@@ -307,7 +306,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
307306
308307 connection . command ( ns ( 'admin.$cmd' ) , cmd , options , ( err , hello ) => {
309308 if ( err ) {
310- return failureHandler ( err ) ;
309+ return failureHandler ( err , isAwaitable ) ;
311310 }
312311
313312 if ( ! ( 'isWritablePrimary' in hello ) ) {
@@ -319,16 +318,14 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
319318 const duration =
320319 isAwaitable && rttPinger ? rttPinger . roundTripTime : calculateDurationInMs ( start ) ;
321320
322- console . log ( 'command' , topologyVersion , hello . topologyVersion , hello ) ;
323- const awaited = useStreamingProtocol ( monitor , hello . topologyVersion ) ;
321+ // I think it's this.
322+ // const awaited = useStreamingProtocol(monitor, hello.topologyVersion);
324323 monitor . emit (
325324 Server . SERVER_HEARTBEAT_SUCCEEDED ,
326- new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , awaited )
325+ new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , isAwaitable )
327326 ) ;
328327
329- // if we are using the streaming protocol then we immediately issue another `started`
330- // event, otherwise the "check" is complete and return to the main monitor loop
331- if ( awaited ) {
328+ if ( isAwaitable ) {
332329 monitor . emit (
333330 Server . SERVER_HEARTBEAT_STARTED ,
334331 new ServerHeartbeatStartedEvent ( monitor . address , true )
@@ -350,7 +347,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
350347 if ( err ) {
351348 monitor [ kConnection ] = undefined ;
352349
353- failureHandler ( err ) ;
350+ failureHandler ( err , false ) ;
354351 return ;
355352 }
356353
@@ -371,7 +368,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
371368 monitor . address ,
372369 calculateDurationInMs ( start ) ,
373370 conn . hello ,
374- false
371+ useStreamingProtocol ( monitor , conn . hello ?. topologyVersion )
375372 )
376373 ) ;
377374
@@ -404,7 +401,6 @@ function monitorServer(monitor: Monitor) {
404401 }
405402
406403 // if the check indicates streaming is supported, immediately reschedule monitoring
407- console . log ( 'checkServerCallback' , hello ?. topologyVersion ) ;
408404 if ( useStreamingProtocol ( monitor , hello ?. topologyVersion ) ) {
409405 setTimeout ( ( ) => {
410406 if ( ! isInCloseState ( monitor ) ) {
0 commit comments