Skip to content

Commit 7892601

Browse files
added getter and using authContext?.authenticating directly
1 parent e9d4f8d commit 7892601

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/cmap/auth/auth_provider.ts

-2
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ export abstract class AuthProvider {
6565
}
6666
try {
6767
context.reauthenticating = true;
68-
context.connection.established = false;
6968
await this.auth(context);
7069
} finally {
7170
context.reauthenticating = false;
72-
context.connection.established = true;
7371
}
7472
}
7573
}

src/cmap/connection.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
275275
);
276276
}
277277

278+
private get shouldEmitAndLogCommand(): boolean {
279+
return (
280+
(this.monitorCommands ||
281+
(this.established &&
282+
!this.authContext?.reauthenticating &&
283+
this.mongoLogger?.willLog(SeverityLevel.DEBUG, MongoLoggableComponent.COMMAND))) ??
284+
false
285+
);
286+
}
287+
278288
public markAvailable(): void {
279289
this.lastUseTime = now();
280290
}
@@ -458,11 +468,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
458468
const message = this.prepareCommand(ns.db, command, options);
459469

460470
let started = 0;
461-
if (
462-
this.monitorCommands ||
463-
(this.established &&
464-
this.mongoLogger?.willLog(SeverityLevel.DEBUG, MongoLoggableComponent.COMMAND))
465-
) {
471+
if (this.shouldEmitAndLogCommand) {
466472
started = now();
467473
this.emitAndLogCommand(
468474
this.monitorCommands,
@@ -488,11 +494,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
488494
throw new MongoServerError(document);
489495
}
490496

491-
if (
492-
this.monitorCommands ||
493-
(this.established &&
494-
this.mongoLogger?.willLog(SeverityLevel.DEBUG, MongoLoggableComponent.COMMAND))
495-
) {
497+
if (this.shouldEmitAndLogCommand) {
496498
this.emitAndLogCommand(
497499
this.monitorCommands,
498500
Connection.COMMAND_SUCCEEDED,
@@ -512,11 +514,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
512514
this.controller.signal.throwIfAborted();
513515
}
514516
} catch (error) {
515-
if (
516-
this.monitorCommands ||
517-
(this.established &&
518-
this.mongoLogger?.willLog(SeverityLevel.DEBUG, MongoLoggableComponent.COMMAND))
519-
) {
517+
if (this.shouldEmitAndLogCommand) {
520518
if (error.name === 'MongoWriteConcernError') {
521519
this.emitAndLogCommand(
522520
this.monitorCommands,

0 commit comments

Comments
 (0)