mongodb/node-mongodb-native · error · MongoRuntimeError

Reauthentication already in progress.

Error message

Reauthentication already in progress.

What it means

Thrown by the base `AuthProvider.reauth()` when called on a connection whose `authContext.reauthenticating` flag is already true. This is the driver's guard against concurrent reauthentication (e.g., OIDC token rotation overlapping on a single connection).

Source

Thrown at src/cmap/auth/auth_provider.ts:68

    _authContext: AuthContext
  ): Promise<HandshakeDocument> {
    return handshakeDoc;
  }

  /**
   * Authenticate
   *
   * @param context - A shared context for authentication flow
   */
  abstract auth(context: AuthContext): Promise<void>;

  /**
   * Reauthenticate.
   * @param context - The shared auth context.
   */
  async reauth(context: AuthContext): Promise<void> {
    if (context.reauthenticating) {
      throw new MongoRuntimeError('Reauthentication already in progress.');
    }
    try {
      context.reauthenticating = true;
      await this.auth(context);
    } finally {
      context.reauthenticating = false;
    }
  }
}

View on GitHub (pinned to 7f8edf30e3)

Solutions

  1. Ensure your application does not reuse a single connection across concurrent ops that can each trigger reauth (use the connection pool normally).
  2. If implementing a custom `AuthProvider`, never call `reauth()` recursively or from multiple parallel paths.
  3. Upgrade the driver — internal reauth coordination improves across versions.
  4. Serialize operations on shared connections during credential rotation.

Example fix

// anti-pattern: manual concurrent reauth
await Promise.all([provider.reauth(ctx), provider.reauth(ctx)]);
// correct: let the driver manage reauth; do not call manually
Defensive patterns

Strategy: validation

Try / catch

try {
  await client.db().command({ ping: 1 });
} catch (e) {
  if (e instanceof MongoRuntimeError && /Reauthentication already in progress/.test(e.message)) {
    // serialize reauth attempts; wait for the in-flight one to complete
  } else throw e;
}

Prevention

When it happens

Trigger: Two reauth attempts race on the same `AuthContext`. The first sets `reauthenticating = true`; the second hits the guard at auth_provider.ts:67 and throws `MongoRuntimeError`.

Common situations: Concurrent operations on one connection both receiving a reauth signal from the server; misbehaving custom auth provider invoking `reauth` directly; race during failover with rotated credentials.

Understand the failure class

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@7f8edf30e3 (2026-08-05). Data as JSON: /api/errors/1fc6dcc0561ae231. Report an issue: GitHub.