From b393200fd32a811340dfe20eeff75660d375c1bf Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Thu, 10 Aug 2017 14:18:34 -0700 Subject: [PATCH] SSE StopAsync should ignore exception (handled elsewhere) (#708) --- .../ServerSentEventsTransport.cs | 10 +++++++++- .../EndToEndTests.cs | 13 ++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs index a9048f3725..9018659ddd 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs @@ -140,7 +140,15 @@ namespace Microsoft.AspNetCore.Sockets.Client _logger.TransportStopping(_connectionId); _transportCts.Cancel(); _application.Out.TryComplete(); - await Running; + + try + { + await Running; + } + catch + { + // exceptions have been handled in the Running task continuation by closing the channel with the exception + } } } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index 004653180b..cf841c9977 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [Fact] - public async Task CanStartConnectionUsingDefaultTransport() + public async Task CanStartAndStopConnectionUsingDefaultTransport() { var url = _serverFixture.BaseUrl + "/echo"; // The test should connect to the server using WebSockets transport on Windows 8 and newer. @@ -53,6 +53,17 @@ namespace Microsoft.AspNetCore.SignalR.Tests await connection.DisposeAsync().OrTimeout(); } + [Theory] + [MemberData(nameof(TransportTypes))] + public async Task CanStartAndStopConnectionUsingGivenTransport(TransportType transportType) + { + var url = _serverFixture.BaseUrl + "/echo"; + // When WebSockets is attempted to be used on Windows 7/2008R2 it will instead use ServerSentEvents + var connection = new HttpConnection(new Uri(url), transportType); + await connection.StartAsync().OrTimeout(); + await connection.DisposeAsync().OrTimeout(); + } + [ConditionalFact] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] public async Task WebSocketsTest()