@@ -2452,16 +2452,20 @@ mon
24522452
24532453 // Test connection
24542454 console . log ( "Testing connection to the added instance..." ) ;
2455- try {
2456- const client = new Client ( { connectionString : connStr } ) ;
2457- await client . connect ( ) ;
2458- const result = await client . query ( "select version();" ) ;
2459- console . log ( "✓ Connection successful" ) ;
2460- console . log ( `${ result . rows [ 0 ] . version } \n` ) ;
2461- await client . end ( ) ;
2462- } catch ( error ) {
2463- const message = error instanceof Error ? error . message : String ( error ) ;
2464- console . error ( `✗ Connection failed: ${ message } \n` ) ;
2455+ {
2456+ let testClient : InstanceType < typeof Client > | null = null ;
2457+ try {
2458+ testClient = new Client ( { connectionString : connStr , connectionTimeoutMillis : 10000 } ) ;
2459+ await testClient . connect ( ) ;
2460+ const result = await testClient . query ( "select version();" ) ;
2461+ console . log ( "✓ Connection successful" ) ;
2462+ console . log ( `${ result . rows [ 0 ] . version } \n` ) ;
2463+ } catch ( error ) {
2464+ const message = error instanceof Error ? error . message : String ( error ) ;
2465+ console . error ( `✗ Connection failed: ${ message } \n` ) ;
2466+ } finally {
2467+ if ( testClient ) await testClient . end ( ) ;
2468+ }
24652469 }
24662470 } else if ( opts . yes ) {
24672471 // Auto-yes mode without database URL - skip database setup
@@ -2496,16 +2500,20 @@ mon
24962500
24972501 // Test connection
24982502 console . log ( "Testing connection to the added instance..." ) ;
2499- try {
2500- const client = new Client ( { connectionString : connStr } ) ;
2501- await client . connect ( ) ;
2502- const result = await client . query ( "select version();" ) ;
2503- console . log ( "✓ Connection successful" ) ;
2504- console . log ( `${ result . rows [ 0 ] . version } \n` ) ;
2505- await client . end ( ) ;
2506- } catch ( error ) {
2507- const message = error instanceof Error ? error . message : String ( error ) ;
2508- console . error ( `✗ Connection failed: ${ message } \n` ) ;
2503+ {
2504+ let testClient : InstanceType < typeof Client > | null = null ;
2505+ try {
2506+ testClient = new Client ( { connectionString : connStr , connectionTimeoutMillis : 10000 } ) ;
2507+ await testClient . connect ( ) ;
2508+ const result = await testClient . query ( "select version();" ) ;
2509+ console . log ( "✓ Connection successful" ) ;
2510+ console . log ( `${ result . rows [ 0 ] . version } \n` ) ;
2511+ } catch ( error ) {
2512+ const message = error instanceof Error ? error . message : String ( error ) ;
2513+ console . error ( `✗ Connection failed: ${ message } \n` ) ;
2514+ } finally {
2515+ if ( testClient ) await testClient . end ( ) ;
2516+ }
25092517 }
25102518 }
25112519 } else {
@@ -3292,7 +3300,7 @@ targets
32923300 console . log ( `Testing connection to monitoring target '${ name } '...` ) ;
32933301
32943302 // Use native pg client instead of requiring psql to be installed
3295- const client = new Client ( { connectionString : instance . conn_str } ) ;
3303+ const client = new Client ( { connectionString : instance . conn_str , connectionTimeoutMillis : 10000 } ) ;
32963304
32973305 try {
32983306 await client . connect ( ) ;
0 commit comments