Fix leaking ssh connections with VS Attach to Process#1552
Open
WardenGnaw wants to merge 1 commit intomainfrom
Open
Fix leaking ssh connections with VS Attach to Process#1552WardenGnaw wants to merge 1 commit intomainfrom
WardenGnaw wants to merge 1 commit 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.
| if (port is IDebugUnixShellPort) | ||
| { | ||
| _unixPort = (IDebugUnixShellPort)port; | ||
| (_unixPort as IDebugPortCleanup)?.AddSessionRef(); |
Member
There was a problem hiding this comment.
Is this going to break other engines that use SSH transport?
| finally | ||
| { | ||
| _connection = null; | ||
| Interlocked.Exchange(ref _sessionRefCount, 0); |
Member
| public void Clean() | ||
| { | ||
| try | ||
| if (Interlocked.Decrement(ref _sessionRefCount) > 0) |
Member
|
|
||
| lock (_lock) | ||
| { | ||
| try |
Member
There was a problem hiding this comment.
Is it possible for us to be shutting down and cleaning up at the same time on different threads? If so, I think we are going to have some race conditions here as:
- We allowed connections to be handed out before
AddSessionRefis called, so those are subject to disposable at any time - Clean can drop
_sessionRefCountto zero, and then another thread can change it to 1, but this code doesn't check that. The easy way to fix this is to stop usingInterlockedto change_sessionRefCountand instead increment/decrement it under the lock.
| } | ||
| catch (Exception ex) | ||
| { | ||
| remoteSystem.Dispose(); |
Member
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.