Found these while looking at a flaky test (#1871)

- Fix crashing test
- Dispose the ClientWebsocket in StopAsync
This commit is contained in:
David Fowler 2018-04-05 12:47:39 -07:00 committed by GitHub
parent b9e88923e7
commit 39f693b9ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -356,6 +356,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal
// exceptions have been handled in the Running task continuation by closing the channel with the exception
return;
}
finally
{
_webSocket.Dispose();
}
Log.TransportStopped(_logger, null);
}

View File

@ -169,13 +169,22 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var restartTcs = new TaskCompletionSource<object>();
connection.Closed += async e =>
{
logger.LogInformation("Closed event triggered");
if (!restartTcs.Task.IsCompleted)
try
{
logger.LogInformation("Restarting connection");
await connection.StartAsync().OrTimeout();
logger.LogInformation("Restarted connection");
restartTcs.SetResult(null);
logger.LogInformation("Closed event triggered");
if (!restartTcs.Task.IsCompleted)
{
logger.LogInformation("Restarting connection");
await connection.StartAsync().OrTimeout();
logger.LogInformation("Restarted connection");
restartTcs.SetResult(null);
}
}
catch (Exception ex)
{
// It's important to try catch here since this happens
// on a thread pool thread
restartTcs.TrySetException(ex);
}
};