0

I've established a tunnel between my laptop and an EC2 instance to use port 27019 locally and port 27017 (MongoDB) remotely.

aws ssm start-session --target "i-someinstance" --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["27017"],"localPortNumber":["27019"]}'

Starting session with SessionId: tedi-0adff9c0a7a4b3ac9
Port 27019 opened for sessionId tedi-0adff9c0a7a4b3ac9.
Connection accepted for session tedi-0adff9c0a7a4b3ac9.

I can then connect to 27017 on localhost:

$ mongo localhost:27019
MongoDB shell version v4.0.0
connecting to: mongodb://localhost:27019/test
MongoDB server version: 4.0.14
qa_primary:PRIMARY>                 

But if I try to establish another connection, this does not seem to be possible - the connection does not succeed and it eventually times out:

$ mongo localhost:27019
MongoDB shell version v4.0.0
connecting to: mongodb://localhost:27019/test

As soon as I close the 1st connection, then the 2nd connection works inmediately.

This is an issue since some Mongo GUI management tools like Robo3T seem to use multiple sockets on the same port to establish a connection and they end up failing. Also it is very convenient to be able to establish multiple connections to the same port for debugging purposes.

5:41:50 PM  Info: Connecting to localhost:27019...
5:43:32 PM  Error: Establish connection failed. Network is unreachable. Reason: network error while attempting to run command 'isMaster' on host 'localhost:27019' . Connection: localhost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.