File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export const LogId = {
12
12
13
13
atlasCheckCredentials : mongoLogId ( 1_001_001 ) ,
14
14
atlasDeleteDatabaseUserFailure : mongoLogId ( 1_001_002 ) ,
15
+ atlasConnectFailure : mongoLogId ( 1_001_003 ) ,
15
16
16
17
telemetryDisabled : mongoLogId ( 1_002_001 ) ,
17
18
telemetryEmitFailure : mongoLogId ( 1_002_002 ) ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { AtlasToolBase } from "../atlasTool.js";
4
4
import { ToolArgs , OperationType } from "../../tool.js" ;
5
5
import { randomBytes } from "crypto" ;
6
6
import { promisify } from "util" ;
7
+ import logger , { LogId } from "../../../logger.js" ;
7
8
8
9
const EXPIRY_MS = 1000 * 60 * 60 * 12 ; // 12 hours
9
10
@@ -100,7 +101,21 @@ export class ConnectClusterTool extends AtlasToolBase {
100
101
cn . searchParams . set ( "authSource" , "admin" ) ;
101
102
const connectionString = cn . toString ( ) ;
102
103
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
+ }
104
119
105
120
return {
106
121
content : [
You can’t perform that action at this time.
0 commit comments