File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed
src/System.Management.Automation/engine/remoting/fanin Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -1488,18 +1488,26 @@ private void CloseConnection()
14881488 var stdErrReader = _stdErrReader ;
14891489 if ( stdErrReader != null ) { stdErrReader . Dispose ( ) ; }
14901490
1491- try
1491+ // The CloseConnection() method can be called multiple times from multiple places.
1492+ // Set the _sshProcessId to zero here so that we go through the work of finding
1493+ // and terminating the SSH process just once.
1494+ var sshProcessId = _sshProcessId ;
1495+ _sshProcessId = 0 ;
1496+ if ( sshProcessId != 0 )
14921497 {
1493- var sshProcess = System . Diagnostics . Process . GetProcessById ( _sshProcessId ) ;
1494- if ( ( sshProcess != null ) && ! sshProcess . HasExited )
1498+ try
14951499 {
1496- sshProcess . Kill ( ) ;
1500+ var sshProcess = System . Diagnostics . Process . GetProcessById ( sshProcessId ) ;
1501+ if ( ( sshProcess != null ) && ( sshProcess . Handle != IntPtr . Zero ) && ! sshProcess . HasExited )
1502+ {
1503+ sshProcess . Kill ( ) ;
1504+ }
14971505 }
1506+ catch ( ArgumentException ) { }
1507+ catch ( InvalidOperationException ) { }
1508+ catch ( NotSupportedException ) { }
1509+ catch ( System . ComponentModel . Win32Exception ) { }
14981510 }
1499- catch ( ArgumentException ) { }
1500- catch ( InvalidOperationException ) { }
1501- catch ( NotSupportedException ) { }
1502- catch ( System . ComponentModel . Win32Exception ) { }
15031511 }
15041512
15051513 private void StartErrorThread (
You can’t perform that action at this time.
0 commit comments