From 2265acde7880fbced32355bcfe0bebe08a097360 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Wed, 8 Aug 2018 14:04:05 -0700 Subject: [PATCH] Don't start stream if already canceled (#2764) --- .../HubConnection.cs | 1 + .../HubConnectionTests.cs | 14 ++------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs index c8a2ebd559..bf15256716 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs @@ -420,6 +420,7 @@ namespace Microsoft.AspNetCore.SignalR.Client { CheckDisposed(); CheckConnectionActive(nameof(StreamAsChannelCoreAsync)); + cancellationToken.ThrowIfCancellationRequested(); var irq = InvocationRequest.Stream(cancellationToken, returnType, _connectionState.GetNextId(), _loggerFactory, this, out channel); await InvokeStreamCore(methodName, irq, args, cancellationToken); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 6ba1bbeb5e..313efa5b5c 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -398,15 +398,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path) { - bool ExpectedErrors(WriteContext writeContext) - { - return (writeContext.LoggerName == nameof(Http.Connections.Client.Internal.ServerSentEventsTransport) || - writeContext.LoggerName == nameof(Http.Connections.Client.Internal.LongPollingTransport)) && - writeContext.EventId.Name == "ErrorSending"; - } - var protocol = HubProtocols[protocolName]; - using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) + using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) { var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); try @@ -416,10 +409,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests var cts = new CancellationTokenSource(); cts.Cancel(); - var channel = await connection.StreamAsChannelAsync("Stream", 5, cts.Token).OrTimeout(); - - await Assert.ThrowsAnyAsync(() => - channel.WaitToReadAsync().AsTask().OrTimeout()); + await Assert.ThrowsAnyAsync(() =>connection.StreamAsChannelAsync("Stream", 5, cts.Token).OrTimeout()); } catch (Exception ex) {