Skip to content

lib/client: reopen an agent connection for each request - #69600

Open
zmb3 wants to merge 3 commits into
masterfrom
zmb3/agentleak
Open

lib/client: reopen an agent connection for each request#69600
zmb3 wants to merge 3 commits into
masterfrom
zmb3/agentleak

Conversation

@zmb3

@zmb3 zmb3 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Our SSH agent client would open a connection to the local SSH agent and then never close it. This is okay for short-lived tsh processes, but leaks connections for long-lived processes like the tsh daemon in Teleport Connect.

This commit introduces a client implementation that establishes a client per-request and closes the connection when the request completes.

Closes #69549
Closes gravitational/customer-sensitive-requests#701

Changelog: fixed an issue that caused Teleport Connect to leak connections to the local SSH agent.

Manual Test Plan

Test Environment

Local Connect (pnpm start-term) connected to platform.teleport.sh.

while true; do echo "[$(date +'%H:%M:%S')] Open sockets: $(lsof "$SSH_AUTH_SOCK" 2>/dev/null | wc -l)"; sleep 5; done

Test Cases

  • Run the lsof loop above in a terminal tab. Navigate around in Connect. Verify connections stay contstant.
  • tsh successfully connects to a Cygwin agent and caches the UID between dials (custom build to force re-dial and log)

@zmb3
zmb3 requested a review from Joerger August 12, 2026 14:17
@github-actions
github-actions Bot requested review from nklaassen and rudream August 12, 2026 14:17
Our SSH agent client would open a connection to the local SSH agent
and then never close it. This is okay for short-lived tsh processes,
but leaks connections for long-lived processes like the tsh daemon
in Teleport Connect.

This commit introduces a client implementation that establishes a
client per-request and closes the connection when the request completes.

@Joerger Joerger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, we just need to use the new single request client here as well.

Edit: nevermind we handle closure correctly there

@zmb3

zmb3 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

Test plan results

Before:

➜ while true; do echo "[$(date +'%H:%M:%S')] Open sockets: $(lsof "$SSH_AUTH_SOCK" 2>/dev/null | wc -l)"; sleep 5; done

[15:49:57] Open sockets:       23
[15:50:02] Open sockets:       23
[15:50:07] Open sockets:       24
[15:50:12] Open sockets:       25
[15:50:17] Open sockets:       26
[15:50:23] Open sockets:       26
[15:50:28] Open sockets:       27

After:

➜ while true; do echo "[$(date +'%H:%M:%S')] Open sockets: $(lsof "$SSH_AUTH_SOCK" 2>/dev/null | wc -l)"; sleep 5; done

[15:50:33] Open sockets:        2
[15:50:38] Open sockets:        2
[15:50:43] Open sockets:        2
[15:50:48] Open sockets:        2
[15:50:53] Open sockets:        2
[15:50:59] Open sockets:        2
[15:51:04] Open sockets:        2
[15:51:09] Open sockets:        2
[15:51:14] Open sockets:        2
[15:51:19] Open sockets:        2
[15:51:24] Open sockets:        2
[15:51:29] Open sockets:        2
[15:51:34] Open sockets:        2
[15:51:40] Open sockets:        2
[15:51:45] Open sockets:        2
[15:51:50] Open sockets:        2
[15:51:55] Open sockets:        2
[15:52:00] Open sockets:        2
[15:52:05] Open sockets:        2
[15:52:10] Open sockets:        2
[15:52:15] Open sockets:        2

@zmb3

zmb3 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: f734efd8b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@zmb3
zmb3 requested a review from gzdunek August 12, 2026 22:08
* Fix nil connection returned from dialCygwin.

* Cache the resolved Cygwin UID so repeated dials can skip UID resolution, which may shell out to Cygwin's slow `ps`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Teleport connect on mac OS leaks domain sockets to SSH_AUTH_SOCK until ssh and teleport connect freezes

3 participants