Merge branch 'release/2.1' into dev
This commit is contained in:
commit
7916f95235
|
|
@ -6,6 +6,7 @@ using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
|
|
@ -640,7 +641,8 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (result.IsCompleted)
|
|
||||||
|
if (result.IsCompleted)
|
||||||
{
|
{
|
||||||
// Not enough data, and we won't be getting any more data.
|
// Not enough data, and we won't be getting any more data.
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
|
|
@ -717,8 +719,13 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (result.IsCompleted)
|
|
||||||
|
if (result.IsCompleted)
|
||||||
{
|
{
|
||||||
|
if (!buffer.IsEmpty)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Connection terminated while reading a message.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -387,12 +387,9 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
await WriteHandshakeResponseAsync(HandshakeResponseMessage.Empty);
|
await WriteHandshakeResponseAsync(HandshakeResponseMessage.Empty);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Didn't parse the handshake");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (result.IsCompleted)
|
|
||||||
|
if (result.IsCompleted)
|
||||||
{
|
{
|
||||||
// connection was closed before we ever received a response
|
// connection was closed before we ever received a response
|
||||||
// can't send a handshake response because there is no longer a connection
|
// can't send a handshake response because there is no longer a connection
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
|
|
@ -198,8 +199,13 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
await _dispatcher.DispatchMessageAsync(connection, message);
|
await _dispatcher.DispatchMessageAsync(connection, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (result.IsCompleted)
|
|
||||||
|
if (result.IsCompleted)
|
||||||
{
|
{
|
||||||
|
if (!buffer.IsEmpty)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Connection terminated while reading a message.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
|
|
@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
testConnection.StartAsync,
|
testConnection.StartAsync,
|
||||||
connection => ((TestConnection)connection).DisposeAsync());
|
connection => ((TestConnection)connection).DisposeAsync());
|
||||||
builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);
|
builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);
|
||||||
|
|
||||||
return builder.Build();
|
return builder.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,6 +451,34 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task HubConnectionClosesWithErrorIfTerminatedWithPartialMessage()
|
||||||
|
{
|
||||||
|
var builder = new HubConnectionBuilder();
|
||||||
|
var innerConnection = new TestConnection();
|
||||||
|
|
||||||
|
var delegateConnectionFactory = new DelegateConnectionFactory(
|
||||||
|
format => innerConnection.StartAsync(format),
|
||||||
|
connection => ((TestConnection)connection).DisposeAsync());
|
||||||
|
builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);
|
||||||
|
|
||||||
|
var hubConnection = builder.Build();
|
||||||
|
var closedEventTcs = new TaskCompletionSource<Exception>();
|
||||||
|
hubConnection.Closed += e =>
|
||||||
|
{
|
||||||
|
closedEventTcs.SetResult(e);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
|
|
||||||
|
await hubConnection.StartAsync().OrTimeout();
|
||||||
|
|
||||||
|
await innerConnection.Application.Output.WriteAsync(Encoding.UTF8.GetBytes(new[] { '{' })).OrTimeout();
|
||||||
|
innerConnection.Application.Output.Complete();
|
||||||
|
|
||||||
|
var exception = await closedEventTcs.Task.OrTimeout();
|
||||||
|
Assert.Equal("Connection terminated while reading a message.", exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task ForceLastInvocationToComplete(TestConnection testConnection)
|
private static async Task ForceLastInvocationToComplete(TestConnection testConnection)
|
||||||
{
|
{
|
||||||
// We need to "complete" the invocation
|
// We need to "complete" the invocation
|
||||||
|
|
|
||||||
|
|
@ -2207,6 +2207,38 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ServerSendsCloseWithErrorWhenConnectionClosedWithPartialMessage()
|
||||||
|
{
|
||||||
|
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services =>
|
||||||
|
{
|
||||||
|
services.AddSignalR(options => options.EnableDetailedErrors = true);
|
||||||
|
});
|
||||||
|
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<SimpleHub>>();
|
||||||
|
|
||||||
|
using (var client = new TestClient())
|
||||||
|
{
|
||||||
|
var connectionHandlerTask = await client.ConnectAsync(connectionHandler).OrTimeout();
|
||||||
|
|
||||||
|
await client.Connection.Application.Output.WriteAsync(Encoding.UTF8.GetBytes(new[] { '{' })).OrTimeout();
|
||||||
|
|
||||||
|
// Close connection
|
||||||
|
client.Connection.Application.Output.Complete();
|
||||||
|
|
||||||
|
// Ignore message from OnConnectedAsync
|
||||||
|
await client.ReadAsync().OrTimeout();
|
||||||
|
|
||||||
|
var closeMessage = Assert.IsType<CloseMessage>(await client.ReadAsync().OrTimeout());
|
||||||
|
|
||||||
|
Assert.Equal("Connection closed with an error. InvalidDataException: Connection terminated while reading a message.", closeMessage.Error);
|
||||||
|
|
||||||
|
// Shut down
|
||||||
|
client.Dispose();
|
||||||
|
|
||||||
|
await connectionHandlerTask.OrTimeout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class CustomHubActivator<THub> : IHubActivator<THub> where THub : Hub
|
private class CustomHubActivator<THub> : IHubActivator<THub> where THub : Hub
|
||||||
{
|
{
|
||||||
public int ReleaseCount;
|
public int ReleaseCount;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue