Skip to content

Fix MongoDB connection leak#60645

Merged
GavinFrazar merged 1 commit intomasterfrom
gavinfrazar/fix-mongodb-connection-leak
Oct 28, 2025
Merged

Fix MongoDB connection leak#60645
GavinFrazar merged 1 commit intomasterfrom
gavinfrazar/fix-mongodb-connection-leak

Conversation

@GavinFrazar
Copy link
Copy Markdown
Contributor

Changelog: Fixed MongoDB topology monitoring connection leak in the Teleport Database Service.

This fixes a topology monitoring connection leak.
The leak was triggered by an error during server selection or the initial auth handshake with the MongoDB server.

I decided to pull this out of the connection pool PR draft since the actual code change to fix the bug is only a few lines and has nothing to do with reducing user<->db agent connection amplification.

Comment on lines +78 to +80
if err := top.Disconnect(ctx); err != nil {
e.Log.WarnContext(e.Context, "Failed to close topology", "error", err)
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the line that actually fixes the leak.
We just needed to disconnect from topology monitoring on errors from server selection or auth handshake.

@GavinFrazar GavinFrazar force-pushed the gavinfrazar/fix-mongodb-connection-leak branch 2 times, most recently from 9619944 to 33e70ea Compare October 28, 2025 06:39
@GavinFrazar GavinFrazar marked this pull request as ready for review October 28, 2025 06:39
@github-actions github-actions bot added database-access Database access related issues and PRs size/sm labels Oct 28, 2025
Comment thread integration/db/db_integration_test.go
Comment thread integration/db/fixture.go Outdated
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/fix-mongodb-connection-leak branch from 33e70ea to b026c2d Compare October 28, 2025 17:05
@GavinFrazar GavinFrazar enabled auto-merge October 28, 2025 17:06
@greedy52
Copy link
Copy Markdown
Contributor

greedy52 commented Oct 28, 2025

FYI, v16 will be EOL by the end of this week. Does the customer have plan to upgrade to a newer version?

This fixes a topology monitoring connection leak.
The leak was triggered by an error during server selection or the
initial auth handshake with the MongoDB server.
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/fix-mongodb-connection-leak branch from b026c2d to 52c9111 Compare October 28, 2025 17:55
@GavinFrazar GavinFrazar added this pull request to the merge queue Oct 28, 2025
Merged via the queue into master with commit ada7572 Oct 28, 2025
42 checks passed
@GavinFrazar GavinFrazar deleted the gavinfrazar/fix-mongodb-connection-leak branch October 28, 2025 18:37
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@GavinFrazar See the table below for backport results.

Branch Result
branch/v17 Failed
branch/v18 Create PR

mmcallister pushed a commit that referenced this pull request Nov 6, 2025
This fixes a topology monitoring connection leak.
The leak was triggered by an error during server selection or the
initial auth handshake with the MongoDB server.
mmcallister pushed a commit that referenced this pull request Nov 19, 2025
This fixes a topology monitoring connection leak.
The leak was triggered by an error during server selection or the
initial auth handshake with the MongoDB server.
mmcallister pushed a commit that referenced this pull request Nov 20, 2025
This fixes a topology monitoring connection leak.
The leak was triggered by an error during server selection or the
initial auth handshake with the MongoDB server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/branch/v17 backport/branch/v18 database-access Database access related issues and PRs db/mongo MongoDB related database access issues size/sm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants