{"record":{"id":"1fc6dcc0561ae231","repo":"mongodb/node-mongodb-native","slug":"reauthentication-already-in-progress","errorCode":null,"errorMessage":"Reauthentication already in progress.","messagePattern":"Reauthentication already in progress\\.","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"error","filePath":"src/cmap/auth/auth_provider.ts","lineNumber":68,"sourceCode":"    _authContext: AuthContext\n  ): Promise<HandshakeDocument> {\n    return handshakeDoc;\n  }\n\n  /**\n   * Authenticate\n   *\n   * @param context - A shared context for authentication flow\n   */\n  abstract auth(context: AuthContext): Promise<void>;\n\n  /**\n   * Reauthenticate.\n   * @param context - The shared auth context.\n   */\n  async reauth(context: AuthContext): Promise<void> {\n    if (context.reauthenticating) {\n      throw new MongoRuntimeError('Reauthentication already in progress.');\n    }\n    try {\n      context.reauthenticating = true;\n      await this.auth(context);\n    } finally {\n      context.reauthenticating = false;\n    }\n  }\n}\n","sourceCodeStart":50,"sourceCodeEnd":78,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/7f8edf30e376738fd554ac232d238e7022bc86a8/src/cmap/auth/auth_provider.ts#L50-L78","documentation":"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).","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// anti-pattern: manual concurrent reauth\nawait Promise.all([provider.reauth(ctx), provider.reauth(ctx)]);\n// correct: let the driver manage reauth; do not call manually","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.db().command({ ping: 1 });\n} catch (e) {\n  if (e instanceof MongoRuntimeError && /Reauthentication already in progress/.test(e.message)) {\n    // serialize reauth attempts; wait for the in-flight one to complete\n  } else throw e;\n}","preventionTips":["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."],"tags":["auth","reauthentication","concurrency","oidc"],"analyzedSha":"7f8edf30e376738fd554ac232d238e7022bc86a8","analyzedAt":"2026-08-05T22:48:45.774Z","schemaVersion":2},"datasetVersion":"2026-08-07T01:17:05.418Z"}