Always check for WebSockets close (#2100)
This commit is contained in:
parent
5516a969e3
commit
9101ab636b
|
|
@ -198,7 +198,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal
|
|||
while (true)
|
||||
{
|
||||
#if NETCOREAPP2_1
|
||||
// Do a 0 byte read so that idle connections don't allocate a buffer when waiting for a read
|
||||
var result = await socket.ReceiveAsync(Memory<byte>.Empty, CancellationToken.None);
|
||||
|
||||
if (result.MessageType == WebSocketMessageType.Close)
|
||||
|
|
@ -223,7 +222,8 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal
|
|||
|
||||
// Exceptions are handled above where the send and receive tasks are being run.
|
||||
var receiveResult = await socket.ReceiveAsync(arraySegment, CancellationToken.None);
|
||||
|
||||
#endif
|
||||
// Need to check again for NetCoreApp2.1 because a close can happen between a 0-byte read and the actual read
|
||||
if (receiveResult.MessageType == WebSocketMessageType.Close)
|
||||
{
|
||||
Log.WebSocketClosed(_logger, _webSocket.CloseStatus);
|
||||
|
|
@ -235,7 +235,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal
|
|||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Log.MessageReceived(_logger, receiveResult.MessageType, receiveResult.Count, receiveResult.EndOfMessage);
|
||||
|
||||
_application.Output.Advance(receiveResult.Count);
|
||||
|
|
|
|||
|
|
@ -154,7 +154,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
|
|||
var memory = _application.Output.GetMemory();
|
||||
|
||||
#if NETCOREAPP2_1
|
||||
// Because we checked the CloseStatus from the 0 byte read above, we don't need to check again after reading
|
||||
var receiveResult = await socket.ReceiveAsync(memory, CancellationToken.None);
|
||||
#else
|
||||
var isArray = MemoryMarshal.TryGetArray<byte>(memory, out var arraySegment);
|
||||
|
|
@ -162,12 +161,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
|
|||
|
||||
// Exceptions are handled above where the send and receive tasks are being run.
|
||||
var receiveResult = await socket.ReceiveAsync(arraySegment, CancellationToken.None);
|
||||
|
||||
#endif
|
||||
// Need to check again for NetCoreApp2.1 because a close can happen between a 0-byte read and the actual read
|
||||
if (receiveResult.MessageType == WebSocketMessageType.Close)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Log.MessageReceived(_logger, receiveResult.MessageType, receiveResult.Count, receiveResult.EndOfMessage);
|
||||
|
||||
_application.Output.Advance(receiveResult.Count);
|
||||
|
|
|
|||
|
|
@ -31,14 +31,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
return true;
|
||||
}
|
||||
|
||||
// Suppress https://github.com/aspnet/SignalR/issues/2069
|
||||
if (writeContext.LoggerName == "Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager" &&
|
||||
writeContext.Message.StartsWith("Failed disposing connection") &&
|
||||
writeContext.Exception is WebSocketException)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue