@@ -1466,6 +1466,9 @@ internal override void CreateAsync()
1466
1466
CloseConnection ( ) ;
1467
1467
} ;
1468
1468
1469
+ // Start error reader thread.
1470
+ StartErrorThread ( _stdErrReader ) ;
1471
+
1469
1472
// Create writer for named pipe.
1470
1473
stdInWriter = new OutOfProcessTextWriter ( _stdInWriter ) ;
1471
1474
@@ -1502,6 +1505,48 @@ private void CloseConnection()
1502
1505
}
1503
1506
}
1504
1507
1508
+ private void StartErrorThread (
1509
+ StreamReader stdErrReader )
1510
+ {
1511
+ Thread errorThread = new Thread ( ProcessErrorThread ) ;
1512
+ errorThread . Name = "SSH Transport Error Thread" ;
1513
+ errorThread . IsBackground = true ;
1514
+ errorThread . Start ( stdErrReader ) ;
1515
+ }
1516
+
1517
+ private void ProcessErrorThread ( object state )
1518
+ {
1519
+ try
1520
+ {
1521
+ StreamReader reader = state as StreamReader ;
1522
+ Dbg . Assert ( reader != null , "Reader cannot be null." ) ;
1523
+
1524
+ while ( true )
1525
+ {
1526
+ string error = reader . ReadLine ( ) ;
1527
+ if ( ! string . IsNullOrEmpty ( error ) && ( error . IndexOf ( "WARNING:" , StringComparison . OrdinalIgnoreCase ) < 0 ) )
1528
+ {
1529
+ // Any SSH client error results in a broken session.
1530
+ PSRemotingTransportException psrte = new PSRemotingTransportException (
1531
+ PSRemotingErrorId . IPCServerProcessReportedError ,
1532
+ RemotingErrorIdStrings . IPCServerProcessReportedError ,
1533
+ error ) ;
1534
+ RaiseErrorHandler ( new TransportErrorOccuredEventArgs ( psrte , TransportMethodEnum . CloseShellOperationEx ) ) ;
1535
+ CloseConnection ( ) ;
1536
+ }
1537
+ }
1538
+ }
1539
+ catch ( ObjectDisposedException ) { }
1540
+ catch ( Exception e )
1541
+ {
1542
+ CommandProcessorBase . CheckForSevereException ( e ) ;
1543
+
1544
+ string errorMsg = ( e . Message != null ) ? e . Message : string . Empty ;
1545
+ _tracer . WriteMessage ( "SSHClientSessionTransportManager" , "ProcessErrorThread" , Guid . Empty ,
1546
+ "Transport manager error thread ended with error: {0}" , errorMsg ) ;
1547
+ }
1548
+ }
1549
+
1505
1550
private void StartReaderThread (
1506
1551
StreamReader reader )
1507
1552
{
@@ -1564,7 +1609,7 @@ private void ProcessReaderThread(object state)
1564
1609
}
1565
1610
1566
1611
string errorMsg = ( e . Message != null ) ? e . Message : string . Empty ;
1567
- _tracer . WriteMessage ( "SSHClientSessionTransportManager" , "StartReaderThread " , Guid . Empty ,
1612
+ _tracer . WriteMessage ( "SSHClientSessionTransportManager" , "ProcessReaderThread " , Guid . Empty ,
1568
1613
"Transport manager reader thread ended with error: {0}" , errorMsg ) ;
1569
1614
}
1570
1615
}
0 commit comments