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
- Ensure your application does not reuse a single connection across concurrent ops that can each trigger reauth (use the connection pool normally).
- If implementing a custom `AuthProvider`, never call `reauth()` recursively or from multiple parallel paths.
- Upgrade the driver — internal reauth coordination improves across versions.
- 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
- Let the driver manage reauth; do not call provider.reauth() directly.
- Avoid issuing concurrent commands on a single shared connection during rotation.
- Use the standard connection pool so each operation gets its own connection.
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
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- username and ENVIRONMENT '${this.mechanismProperties.ENVIRON
- No password is allowed in ENVIRONMENT '${this.mechanismPrope
- TOKEN_RESOURCE must be set in the auth mechanism properties
- Currently only a ENVIRONMENT in ${ALLOWED_ENVIRONMENT_NAMES.
- Either a ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK
AI-assisted analysis of mongodb/node-mongodb-native@7f8edf30e3 (2026-08-05).
Data as JSON: /api/errors/1fc6dcc0561ae231.
Report an issue: GitHub.