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()
1488
1488
var stdErrReader = _stdErrReader ;
1489
1489
if ( stdErrReader != null ) { stdErrReader . Dispose ( ) ; }
1490
1490
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 )
1492
1497
{
1493
- var sshProcess = System . Diagnostics . Process . GetProcessById ( _sshProcessId ) ;
1494
- if ( ( sshProcess != null ) && ! sshProcess . HasExited )
1498
+ try
1495
1499
{
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
+ }
1497
1505
}
1506
+ catch ( ArgumentException ) { }
1507
+ catch ( InvalidOperationException ) { }
1508
+ catch ( NotSupportedException ) { }
1509
+ catch ( System . ComponentModel . Win32Exception ) { }
1498
1510
}
1499
- catch ( ArgumentException ) { }
1500
- catch ( InvalidOperationException ) { }
1501
- catch ( NotSupportedException ) { }
1502
- catch ( System . ComponentModel . Win32Exception ) { }
1503
1511
}
1504
1512
1505
1513
private void StartErrorThread (
You can’t perform that action at this time.
0 commit comments