@@ -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 ] ;
@@ -242,25 +241,19 @@ function useStreamingProtocol(monitor: Monitor, topologyVersion: TopologyVersion
242
241
function checkServer ( monitor : Monitor , callback : Callback < Document | null > ) {
243
242
let start = now ( ) ;
244
243
const topologyVersion = monitor [ kServer ] . description . topologyVersion ;
245
- console . log ( 'checkServer' , topologyVersion ) ;
246
244
const isAwaitable = useStreamingProtocol ( monitor , topologyVersion ) ;
247
245
monitor . emit (
248
246
Server . SERVER_HEARTBEAT_STARTED ,
249
247
new ServerHeartbeatStartedEvent ( monitor . address , isAwaitable )
250
248
) ;
251
249
252
- function failureHandler ( err : Error ) {
250
+ function failureHandler ( err : Error , awaited : boolean ) {
253
251
monitor [ kConnection ] ?. destroy ( { force : true } ) ;
254
252
monitor [ kConnection ] = undefined ;
255
253
256
254
monitor . emit (
257
255
Server . SERVER_HEARTBEAT_FAILED ,
258
- new ServerHeartbeatFailedEvent (
259
- monitor . address ,
260
- calculateDurationInMs ( start ) ,
261
- err ,
262
- isAwaitable
263
- )
256
+ new ServerHeartbeatFailedEvent ( monitor . address , calculateDurationInMs ( start ) , err , awaited )
264
257
) ;
265
258
266
259
const error = ! ( err instanceof MongoError )
@@ -307,7 +300,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
307
300
308
301
connection . command ( ns ( 'admin.$cmd' ) , cmd , options , ( err , hello ) => {
309
302
if ( err ) {
310
- return failureHandler ( err ) ;
303
+ return failureHandler ( err , isAwaitable ) ;
311
304
}
312
305
313
306
if ( ! ( 'isWritablePrimary' in hello ) ) {
@@ -319,16 +312,12 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
319
312
const duration =
320
313
isAwaitable && rttPinger ? rttPinger . roundTripTime : calculateDurationInMs ( start ) ;
321
314
322
- console . log ( 'command' , topologyVersion , hello . topologyVersion , hello ) ;
323
- const awaited = useStreamingProtocol ( monitor , hello . topologyVersion ) ;
324
315
monitor . emit (
325
316
Server . SERVER_HEARTBEAT_SUCCEEDED ,
326
- new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , awaited )
317
+ new ServerHeartbeatSucceededEvent ( monitor . address , duration , hello , isAwaitable )
327
318
) ;
328
319
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 ) {
320
+ if ( isAwaitable ) {
332
321
monitor . emit (
333
322
Server . SERVER_HEARTBEAT_STARTED ,
334
323
new ServerHeartbeatStartedEvent ( monitor . address , true )
@@ -350,7 +339,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
350
339
if ( err ) {
351
340
monitor [ kConnection ] = undefined ;
352
341
353
- failureHandler ( err ) ;
342
+ failureHandler ( err , false ) ;
354
343
return ;
355
344
}
356
345
@@ -371,7 +360,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
371
360
monitor . address ,
372
361
calculateDurationInMs ( start ) ,
373
362
conn . hello ,
374
- false
363
+ useStreamingProtocol ( monitor , conn . hello ?. topologyVersion )
375
364
)
376
365
) ;
377
366
@@ -404,7 +393,6 @@ function monitorServer(monitor: Monitor) {
404
393
}
405
394
406
395
// if the check indicates streaming is supported, immediately reschedule monitoring
407
- console . log ( 'checkServerCallback' , hello ?. topologyVersion ) ;
408
396
if ( useStreamingProtocol ( monitor , hello ?. topologyVersion ) ) {
409
397
setTimeout ( ( ) => {
410
398
if ( ! isInCloseState ( monitor ) ) {
0 commit comments