Skip to content

Commit ffd8b52

Browse files
committed
fix: bad auth when connecting to atlas clusters
1 parent de2c604 commit ffd8b52

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const LogId = {
1212

1313
atlasCheckCredentials: mongoLogId(1_001_001),
1414
atlasDeleteDatabaseUserFailure: mongoLogId(1_001_002),
15+
atlasConnectFailure: mongoLogId(1_001_003),
1516

1617
telemetryDisabled: mongoLogId(1_002_001),
1718
telemetryEmitFailure: mongoLogId(1_002_002),

src/tools/atlas/metadata/connectCluster.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AtlasToolBase } from "../atlasTool.js";
44
import { ToolArgs, OperationType } from "../../tool.js";
55
import { randomBytes } from "crypto";
66
import { promisify } from "util";
7+
import logger, { LogId } from "../../../logger.js";
78

89
const EXPIRY_MS = 1000 * 60 * 60 * 12; // 12 hours
910

@@ -100,7 +101,21 @@ export class ConnectClusterTool extends AtlasToolBase {
100101
cn.searchParams.set("authSource", "admin");
101102
const connectionString = cn.toString();
102103

103-
await this.session.connectToMongoDB(connectionString, this.config.connectOptions);
104+
for (let i = 0; i < 20; i++) {
105+
try {
106+
await this.session.connectToMongoDB(connectionString, this.config.connectOptions);
107+
break;
108+
} catch (err: unknown) {
109+
const error = err instanceof Error ? err : new Error(String(err));
110+
logger.debug(
111+
LogId.atlasConnectFailure,
112+
"atlas-connect-cluster",
113+
`error connecting to cluster: ${error.message}`
114+
);
115+
116+
await new Promise((resolve) => setTimeout(resolve, 500));
117+
}
118+
}
104119

105120
return {
106121
content: [

0 commit comments

Comments
 (0)