Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo clients with serverSelectionTimeoutMS set to 5000 #13408

Merged
merged 5 commits into from
Jun 24, 2022

Conversation

greedy52
Copy link
Contributor

@greedy52 greedy52 commented Jun 13, 2022

fixes #13195

Testing:

  • tsh db connect
    • mongosh: works as expected, can use the env var to test scenarios
    • mongo: connects fine with provided URL but never times out - I think the client is ignoring the parameter.
    • Tested with an empty or a specific database name. Both work as expected.
  • tsh proxy db --tunnel works as expected

Note:
This is a temporary solution that tries to resolve most situations. Further investigation will be conducted to find why tsh db connect takes very long.
Another temporary workaround that can be done by the user is to downgrade to old mongo client instead of using mongosh

@greedy52 greedy52 added tsh tsh - Teleport's command line tool for logging into nodes running Teleport. db/mongo MongoDB related database access issues labels Jun 13, 2022
@greedy52 greedy52 changed the title Mongo clients with serverSelectionTimeoutMS Mongo clients with serverSelectionTimeoutMS set to 5000 Jun 13, 2022
@greedy52 greedy52 requested review from smallinsky, jakule and r0mant June 22, 2022 17:39
@greedy52 greedy52 self-assigned this Jun 22, 2022
@greedy52 greedy52 marked this pull request as ready for review June 22, 2022 17:39
@github-actions github-actions bot requested review from lxea and zmb3 June 22, 2022 17:40
lib/client/db/dbcmd/dbcmd.go Outdated Show resolved Hide resolved
lib/client/db/dbcmd/dbcmd.go Outdated Show resolved Hide resolved
if c.options.printFormat {
return fmt.Sprintf(`"%s"`, address.String())
}
return address.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to quote the connectionString to mitigate shell parsing errors ?
So instead of invoking mongosh mongodb://localhost:12345/mydb?serverSelectionTimeoutMS=5000 we should alywas call mongosh "mongodb://localhost:12345/mydb?serverSelectionTimeoutMS=5000" even if TLS routing is disabled ?

Copy link
Contributor Author

@greedy52 greedy52 Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quoted URL will fail exec.Cmd.Run as clients sees the quotation as invalid URL.

I tested this with Teleport Connect today and I've added WithPrintFormat for it to make sure postgres and mongo connection urls are quoted. And also added some more comments on WithPrintFormat

after fix:
Screen Shot 2022-06-23 at 10 29 58 AM

I've also added @ravicious for review on that part.

@greedy52 greedy52 requested review from ravicious and smallinsky June 23, 2022 14:45
lib/srv/db/mongodb/connect.go Outdated Show resolved Hide resolved
Copy link
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this on a Connect build and I managed to successfully connect to my mongo instance.

@greedy52
Copy link
Contributor Author

Thanks @ravicious for confirming =D

@greedy52 greedy52 enabled auto-merge (squash) June 24, 2022 14:16
@greedy52 greedy52 merged commit 8cb7522 into master Jun 24, 2022
@github-actions
Copy link

@greedy52 See the table below for backport results.

Branch Result
branch/v10 Create PR
branch/v9 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db/mongo MongoDB related database access issues tsh tsh - Teleport's command line tool for logging into nodes running Teleport.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mongo timeouts to Atlas from tsh db connect
3 participants