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 engine creates 3 connections to db server per incoming connection. #10950

Open
greedy52 opened this issue Mar 8, 2022 · 1 comment
Open
Labels
bug database-access Database access related issues and PRs db/mongo MongoDB related database access issues

Comments

@greedy52
Copy link
Contributor

greedy52 commented Mar 8, 2022

Description

What happened:
While investigating #10869, the mongo client is found to create 3 connections per mongo.Connect.

Once our mongo engine receives these 3 connections, then it creates 3 connections to the db server per incoming connection so 3 x 3 = 9 connections are established to db server in total

[mongo client] ---x3---> [teleport] ---x9---> [mongo server]

What you expected to happen:
Teleport should NOT multiply number of connections to the server

Reproduction Steps

As minimally and precisely as possible, describe step-by-step how to reproduce the problem.

  1. Add some debug logs for TestDatabaseAccessMongoConnectionCount in integration test

Server Details

  • Teleport version (run teleport version): v9

Client Details

  • Tsh version (tsh version): n/a

Debug Logs

For a single test client, that does one find, test server receives

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60959, command isMaster name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60959, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60960, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60961, command authenticate name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60961, command isMaster name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60961, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60962, command isMaster name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60962, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60963, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60964, command authenticate name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60964, command isMaster name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60964, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60966, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60967, command isMaster name:root-mongo mongodb/test.go:172

2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60968, command authenticate name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60968, command isMaster name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60968, command ping name:root-mongo mongodb/test.go:172
2022-03-08T08:28:28-05:00 DEBU [MONGODB]   TestServer.handleConnection, connection 127.0.0.1:60968, command find name:root-mongo mongodb/test.go:172

Possible solutions

We may have to modify the mongo driver to disable some background connections that are not necessary for our proxy.

@greedy52 greedy52 added bug database-access Database access related issues and PRs db/mongo MongoDB related database access issues labels Mar 8, 2022
@greedy52 greedy52 self-assigned this Mar 8, 2022
@greedy52 greedy52 removed their assignment Mar 17, 2022
@greedy52
Copy link
Contributor Author

greedy52 commented Sep 22, 2023

Tested with

  • Teleport v14
  • mongosh 2.0.1
  • Mongo Atlas 6.0.10

Per tsh db connect

  • Teleport Database agent sees 6 sessions
  • Mongo Atlas Primary shard sees 18 connections, Secondary sees 12 connections

Seems number of connections can be reduced by setting maxPoolSize=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug database-access Database access related issues and PRs db/mongo MongoDB related database access issues
Projects
None yet
Development

No branches or pull requests

1 participant