Added try finally to semaphore release (#1469)

This commit is contained in:
David Fowler 2018-02-18 12:37:42 -08:00 committed by GitHub
parent 03ca505fb3
commit a2ac9c573e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 8 deletions

View File

@ -85,19 +85,24 @@ namespace Microsoft.AspNetCore.SignalR
public virtual async Task WriteAsync(HubMessage message)
{
await _writeLock.WaitAsync();
try
{
await _writeLock.WaitAsync();
var buffer = ProtocolReaderWriter.WriteMessage(message);
var buffer = ProtocolReaderWriter.WriteMessage(message);
_connectionContext.Transport.Output.Write(buffer);
_connectionContext.Transport.Output.Write(buffer);
Interlocked.Exchange(ref _lastSendTimestamp, Stopwatch.GetTimestamp());
Interlocked.Exchange(ref _lastSendTimestamp, Stopwatch.GetTimestamp());
await _connectionContext.Transport.Output.FlushAsync(CancellationToken.None);
_writeLock.Release();
await _connectionContext.Transport.Output.FlushAsync(CancellationToken.None);
}
finally
{
_writeLock.Release();
}
}
public virtual void Abort()
{
// If we already triggered the token then noop, this isn't thread safe but it's good enough