Fix leaking ssh connections with VS Attach to Process#1552
Open
WardenGnaw wants to merge 2 commits intomainfrom
Open
Fix leaking ssh connections with VS Attach to Process#1552WardenGnaw wants to merge 2 commits intomainfrom
WardenGnaw wants to merge 2 commits intomainfrom
Conversation
This PR address the issue where every SSH PortSupplier AD7Port will always create a new SSH connection on the remote machine when the Attach to Process window opens and closes. This causes ports to be kept open until VS completly closes. The changes here are to cache an existing connection if VS opens and closes the attach to process window. Adds a ref count mechanism to ensure if you are debugging multiple processes on the same machine, it does not Clean the connection until all processes are done.
| lock (_lock) | ||
| { | ||
| _activeAsyncCommands++; | ||
| } |
Member
There was a problem hiding this comment.
Should this happen before we call GetConnection so that we don't have a race where:
- GetConnection returns a connection
- some other async command finishes, disconnecting
- We try and use the connection which is now closed
| { | ||
| _inner.Abort(); | ||
| // If OnExit didn't fire (abort path), notify the port now | ||
| if (Interlocked.CompareExchange(ref _notified, 1, 0) == 0) |
Member
There was a problem hiding this comment.
Instead of having _notified in this class, should we move this to AsyncCommandCallback to handle possible races when Abort is called at roughly the same time as OnExit.
| { | ||
| lock (_lock) | ||
| { | ||
| _activeAsyncCommands--; |
Member
| { | ||
| _activeAsyncCommands++; | ||
| } | ||
| connection.BeginExecuteAsyncCommand(commandText, runInShell, wrappedCallback, out asyncCommand); |
Member
| Debug.Assert(_sessionRefCount > 0, "Unbalanced call to Clean -- no matching AddSessionRef"); | ||
| _sessionRefCount--; | ||
|
|
||
| if (_sessionRefCount > 0) |
Member
gregg-miskelly
requested changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR address the issue where every SSH PortSupplier AD7Port will always create a new SSH connection on the remote machine when the Attach to Process window opens and closes. This causes ports to be kept open until VS completly closes.
The changes here are to cache an existing connection if VS opens and closes the attach to process window.
Adds a ref count mechanism to ensure if you are debugging multiple processes on the same machine, it does not Clean the connection until all processes are done.
Testing:
Ran
ss -t state established sport = :22to see how many connections exist.