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 // exceptions have been handled in the Running task continuation by closing the channel with the exception
return; return;
} }
finally
{
_webSocket.Dispose();
}
Log.TransportStopped(_logger, null); Log.TransportStopped(_logger, null);
} }

View File

@ -169,13 +169,22 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var restartTcs = new TaskCompletionSource<object>(); var restartTcs = new TaskCompletionSource<object>();
connection.Closed += async e => connection.Closed += async e =>
{ {
logger.LogInformation("Closed event triggered"); try
if (!restartTcs.Task.IsCompleted)
{ {
logger.LogInformation("Restarting connection"); logger.LogInformation("Closed event triggered");
await connection.StartAsync().OrTimeout(); if (!restartTcs.Task.IsCompleted)
logger.LogInformation("Restarted connection"); {
restartTcs.SetResult(null); 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);
} }
}; };