Commit 092c5ac9 authored by Marc Gravell's avatar Marc Gravell

be less twitchy about errors from Read that happen once we've already burned the pipe

parent a9790b9e
......@@ -155,8 +155,8 @@ internal void OnInternalError(Exception exception, EndPoint endpoint = null, Con
{
try
{
Trace("Internal error: " + origin + ", " + exception == null ? "unknown" : exception.Message);
if (_isDisposed) return;
Trace("Internal error: " + origin + ", " + exception == null ? "unknown" : exception.Message);
var handler = InternalError;
if (handler != null)
{
......
......@@ -1274,9 +1274,9 @@ private void OnDebugAbort()
private async void ReadFromPipe() // yes it is an async void; deal with it!
{
bool allowSyncRead = true, isReading = false;
try
{
bool allowSyncRead = true;
while (true)
{
var input = _ioPipe?.Input;
......@@ -1284,10 +1284,12 @@ private void OnDebugAbort()
// note: TryRead will give us back the same buffer in a tight loop
// - so: only use that if we're making progress
isReading = true;
if (!(allowSyncRead && input.TryRead(out var readResult)))
{
readResult = await input.ReadAsync().ForAwait();
}
isReading = false;
var buffer = readResult.Buffer;
int handled = 0;
......@@ -1310,11 +1312,21 @@ private void OnDebugAbort()
RecordConnectionFailed(ConnectionFailureType.SocketClosed);
}
catch (Exception ex)
{
// this CEX is just a hardcore "seriously, read the actual value" - there's no
// convenient "Thread.VolatileRead<T>(ref T field) where T : class", and I don't
// want to make the field volatile just for this one place that needs it
if (isReading && Interlocked.CompareExchange(ref _ioPipe, null, null) == null)
{
// yeah, that's fine... don't worry about it
}
else
{
Trace("Faulted");
RecordConnectionFailed(ConnectionFailureType.InternalFailure, ex);
}
}
}
private int ProcessBuffer(ref ReadOnlySequence<byte> buffer)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment