Skip to content

Commit 9ace7a0

Browse files
reauth support for connection.established
1 parent cbb5df6 commit 9ace7a0

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/cmap/auth/auth_provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ export abstract class AuthProvider {
6565
}
6666
try {
6767
context.reauthenticating = true;
68+
context.connection.established = false;
6869
await this.auth(context);
6970
} finally {
7071
context.reauthenticating = false;
72+
context.connection.established = true;
7173
}
7274
}
7375
}

src/cmap/connection.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
174174
* - TCP handshake
175175
* - TLS negotiated
176176
* - mongodb handshake (saslStart, saslContinue), includes authentication
177+
*
177178
* Once connection is established, command logging can log events (if enabled)
178179
*/
179180
public established: boolean;
@@ -186,8 +187,6 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
186187
private messageStream: Readable;
187188
private socketWrite: (buffer: Uint8Array) => Promise<void>;
188189
private clusterTime: Document | null = null;
189-
/** @internal */
190-
override component = MongoLoggableComponent.COMMAND;
191190
/** @internal */
192191
override mongoLogger: MongoLogger | undefined;
193192

@@ -461,7 +460,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
461460
let started = 0;
462461
if (
463462
this.monitorCommands ||
464-
(this.established && this.mongoLogger?.willLog(SeverityLevel.DEBUG, this.component))
463+
(this.established && this.mongoLogger?.willLog(SeverityLevel.DEBUG, MongoLoggableComponent.COMMAND))
465464
) {
466465
started = now();
467466
this.emitAndLogCommand(
@@ -490,7 +489,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
490489

491490
if (
492491
this.monitorCommands ||
493-
(this.established && this.mongoLogger?.willLog(SeverityLevel.DEBUG, this.component))
492+
(this.established && this.mongoLogger?.willLog(SeverityLevel.DEBUG, MongoLoggableComponent.COMMAND))
494493
) {
495494
this.emitAndLogCommand(
496495
this.monitorCommands,
@@ -513,7 +512,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
513512
} catch (error) {
514513
if (
515514
this.monitorCommands ||
516-
(this.established && this.mongoLogger?.willLog(SeverityLevel.DEBUG, this.component))
515+
(this.established && this.mongoLogger?.willLog(SeverityLevel.DEBUG, MongoLoggableComponent.COMMAND))
517516
) {
518517
if (error.name === 'MongoWriteConcernError') {
519518
this.emitAndLogCommand(

src/mongo_types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export class TypedEventEmitter<Events extends EventsDescription> extends EventEm
456456
if (monitorCommands) {
457457
this.emit(event, ...args);
458458
}
459-
if (this.component && connectionEstablished) {
459+
if (connectionEstablished) {
460460
const loggableCommandEvent:
461461
| CommandStartedEvent
462462
| LoggableCommandFailedEvent

0 commit comments

Comments
 (0)