File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,7 @@ class MongoshNodeRepl implements EvaluationListener {
187
187
}
188
188
await this . greet ( mongodVersion ) ;
189
189
await this . printStartupLog ( instanceState ) ;
190
+ await this . printBasicConnectivityWarning ( instanceState ) ;
190
191
191
192
this . inspectCompact = await this . getConfig ( 'inspectCompact' ) ;
192
193
this . inspectDepth = await this . getConfig ( 'inspectDepth' ) ;
@@ -459,6 +460,27 @@ class MongoshNodeRepl implements EvaluationListener {
459
460
this . output . write ( text ) ;
460
461
}
461
462
463
+ /**
464
+ * Print a warning if the server is not able to respond to commands.
465
+ * This can happen in load balanced mode, for example.
466
+ */
467
+ async printBasicConnectivityWarning ( instanceState : ShellInstanceState ) : Promise < void > {
468
+ if ( this . shellCliOptions . nodb || this . shellCliOptions . quiet ) {
469
+ return ;
470
+ }
471
+
472
+ let err : Error ;
473
+ try {
474
+ await instanceState . currentDb . adminCommand ( { ping : 1 } ) ;
475
+ return ;
476
+ } catch ( error : any ) {
477
+ err = error ;
478
+ }
479
+
480
+ const text = this . clr ( 'The server failed to respond to a ping and may be unavailable:' , [ 'bold' , 'yellow' ] ) ;
481
+ this . output . write ( text + '\n' + this . formatError ( err ) + '\n' ) ;
482
+ }
483
+
462
484
/**
463
485
* Evaluate a piece of input code. This is called by the AsyncRepl eval function
464
486
* and calls the {@link ShellEvaluator} eval function, passing along all of its
Original file line number Diff line number Diff line change @@ -1141,6 +1141,15 @@ describe('e2e', function() {
1141
1141
} ) ;
1142
1142
} ) ;
1143
1143
1144
+ describe ( 'with incomplete loadBalanced connectivity' , ( ) => {
1145
+ it ( 'prints a warning at startup' , async ( ) => {
1146
+ const shell = TestShell . start ( { args : [ 'mongodb://localhost:1/?loadBalanced=true' ] } ) ;
1147
+ await shell . waitForPrompt ( ) ;
1148
+ shell . assertContainsOutput ( 'The server failed to respond to a ping and may be unavailable' ) ;
1149
+ shell . assertContainsOutput ( 'MongoNetworkError' ) ;
1150
+ } ) ;
1151
+ } ) ;
1152
+
1144
1153
describe ( 'run Node.js scripts as-is' , ( ) => {
1145
1154
it ( 'runs Node.js scripts as they are when using MONGOSH_RUN_NODE_SCRIPT' , async ( ) => {
1146
1155
const filename = path . resolve ( __dirname , 'fixtures' , 'simple-console-log.js' ) ;
You can’t perform that action at this time.
0 commit comments