Improve exception diagnostics for stdio client (#376)
* Improve exception diagnostics for stdio client Track the last several lines of stderr and include those in an exception created as part of CleanupAsync if the server process has already exited. This is based on an assumption that the server should never exit prior to CleanupAsync being called. * Address feedback and fix test failure
This commit is contained in:
parent
8d4f51da50
commit
c11c634945
1 changed files with 222 additions and 131 deletions
|
|
@ -51,7 +51,7 @@ public class StreamServerTransport : TransportBase
|
|||
_inputReader = new StreamReader(inputStream, Encoding.UTF8);
|
||||
_outputStream = outputStream;
|
||||
|
||||
SetConnected(true);
|
||||
SetConnected();
|
||||
_readLoopCompleted = Task.Run(ReadMessagesAsync, _shutdownCts.Token);
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ public class StreamServerTransport : TransportBase
|
|||
{
|
||||
if (!IsConnected)
|
||||
{
|
||||
throw new InvalidOperationException("Transport is not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
using var _ = await _sendLock.LockAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
|
@ -80,13 +80,14 @@ public class StreamServerTransport : TransportBase
|
|||
catch (Exception ex)
|
||||
{
|
||||
LogTransportSendFailed(Name, id, ex);
|
||||
throw new InvalidOperationException("Failed to send message", ex);
|
||||
throw new IOException("Failed to send message.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ReadMessagesAsync()
|
||||
{
|
||||
CancellationToken shutdownToken = _shutdownCts.Token;
|
||||
Exception? error = null;
|
||||
try
|
||||
{
|
||||
LogTransportEnteringReadMessagesLoop(Name);
|
||||
|
|
@ -140,10 +141,11 @@ public class StreamServerTransport : TransportBase
|
|||
catch (Exception ex)
|
||||
{
|
||||
LogTransportReadMessagesFailed(Name, ex);
|
||||
error = ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
SetConnected(false);
|
||||
SetDisconnected(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +185,7 @@ public class StreamServerTransport : TransportBase
|
|||
}
|
||||
finally
|
||||
{
|
||||
SetConnected(false);
|
||||
SetDisconnected();
|
||||
LogTransportShutDown(Name);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue