Don't start stream if already canceled (#2764)
This commit is contained in:
parent
186a85b7e0
commit
2265acde78
|
|
@ -420,6 +420,7 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
||||||
{
|
{
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
CheckConnectionActive(nameof(StreamAsChannelCoreAsync));
|
CheckConnectionActive(nameof(StreamAsChannelCoreAsync));
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var irq = InvocationRequest.Stream(cancellationToken, returnType, _connectionState.GetNextId(), _loggerFactory, this, out channel);
|
var irq = InvocationRequest.Stream(cancellationToken, returnType, _connectionState.GetNextId(), _loggerFactory, this, out channel);
|
||||||
await InvokeStreamCore(methodName, irq, args, cancellationToken);
|
await InvokeStreamCore(methodName, irq, args, cancellationToken);
|
||||||
|
|
|
||||||
|
|
@ -398,15 +398,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
||||||
public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
|
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];
|
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);
|
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory);
|
||||||
try
|
try
|
||||||
|
|
@ -416,10 +409,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
cts.Cancel();
|
cts.Cancel();
|
||||||
|
|
||||||
var channel = await connection.StreamAsChannelAsync<int>("Stream", 5, cts.Token).OrTimeout();
|
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>connection.StreamAsChannelAsync<int>("Stream", 5, cts.Token).OrTimeout());
|
||||||
|
|
||||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>
|
|
||||||
channel.WaitToReadAsync().AsTask().OrTimeout());
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue