@@ -120,7 +120,6 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
120
120
minHeartbeatFrequencyMS : options . minHeartbeatFrequencyMS ?? 500 ,
121
121
serverMonitoringMode : options . serverMonitoringMode
122
122
} ) ;
123
- console . log ( getFAASEnv ( ) ) ;
124
123
this . isRunningInFaasEnv = getFAASEnv ( ) != null ;
125
124
126
125
const cancellationToken = this [ kCancellationToken ] ;
@@ -241,15 +240,8 @@ function useStreamingProtocol(monitor: Monitor, topologyVersion: TopologyVersion
241
240
242
241
function checkServer ( monitor : Monitor , callback : Callback < Document | null > ) {
243
242
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 ) {
253
245
monitor [ kConnection ] ?. destroy ( { force : true } ) ;
254
246
monitor [ kConnection ] = undefined ;
255
247
@@ -281,6 +273,13 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
281
273
const connectTimeoutMS = monitor . options . connectTimeoutMS ;
282
274
const maxAwaitTimeMS = monitor . options . heartbeatFrequencyMS ;
283
275
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
+
284
283
const cmd = {
285
284
[ serverApi ?. version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND ] : 1 ,
286
285
...( isAwaitable && topologyVersion
@@ -307,7 +306,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
307
306
308
307
connection . command ( ns ( 'admin.$cmd' ) , cmd , options , ( err , hello ) => {
309
308
if ( err ) {
310
- return failureHandler ( err ) ;
309
+ return failureHandler ( err , isAwaitable ) ;
311
310
}
312
311
313
312
if ( ! ( 'isWritablePrimary' in hello ) ) {
@@ -319,16 +318,14 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
319
318
const duration =
320
319
isAwaitable && rttPinger ? rttPinger . roundTripTime : calculateDurationInMs ( start ) ;
321
320
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);
324
323
monitor . emit (
325
324
Server . SERVER_HEARTBEAT_SUCCEEDED ,
326
- new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , awaited )
325
+ new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , isAwaitable )
327
326
) ;
328
327
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 ) {
332
329
monitor . emit (
333
330
Server . SERVER_HEARTBEAT_STARTED ,
334
331
new ServerHeartbeatStartedEvent ( monitor . address , true )
@@ -350,7 +347,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
350
347
if ( err ) {
351
348
monitor [ kConnection ] = undefined ;
352
349
353
- failureHandler ( err ) ;
350
+ failureHandler ( err , false ) ;
354
351
return ;
355
352
}
356
353
@@ -371,7 +368,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
371
368
monitor . address ,
372
369
calculateDurationInMs ( start ) ,
373
370
conn . hello ,
374
- false
371
+ useStreamingProtocol ( monitor , conn . hello ?. topologyVersion )
375
372
)
376
373
) ;
377
374
@@ -404,7 +401,6 @@ function monitorServer(monitor: Monitor) {
404
401
}
405
402
406
403
// if the check indicates streaming is supported, immediately reschedule monitoring
407
- console . log ( 'checkServerCallback' , hello ?. topologyVersion ) ;
408
404
if ( useStreamingProtocol ( monitor , hello ?. topologyVersion ) ) {
409
405
setTimeout ( ( ) => {
410
406
if ( ! isInCloseState ( monitor ) ) {
0 commit comments