Skip to content

Commit

Permalink
Revert "Stop processing messages before ending the WebSocketFunc Task"
Browse files Browse the repository at this point in the history
This reverts commit 654bfb4.
  • Loading branch information
halter73 committed Dec 12, 2014
1 parent ea883ae commit c213737
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/Microsoft.AspNet.SignalR.Core/Owin/OwinWebSocketHandler.cs
Expand Up @@ -74,29 +74,35 @@ public Task ProcessRequest(IDictionary<string, object> environment)

var cts = new CancellationTokenSource();
var webSocketHandler = new DefaultWebSocketHandler(_maxIncomingMessageSize);
var task = webSocketHandler.ProcessWebSocketRequestAsync(webSocket, cts.Token);

return Task.WhenAll(webSocketHandler.ProcessWebSocketRequestAsync(webSocket, cts.Token),
RunWebSocketHandler(webSocketHandler, cts));
RunWebSocketHandler(webSocketHandler, cts);

return task;
}

private async Task RunWebSocketHandler(DefaultWebSocketHandler handler, CancellationTokenSource cts)
private void RunWebSocketHandler(DefaultWebSocketHandler handler, CancellationTokenSource cts)
{
try
{
await _callback(handler).PreserveCulture();
}
catch
// async void methods are not supported in ASP.NET and they throw a InvalidOperationException.
Task.Run(async () =>
{
// This error was already handled by other layers
// we can no-op here so we don't cause an unobserved exception
}
try
{
await _callback(handler).PreserveCulture();
}
catch
{
// This error was already handled by other layers
// we can no-op here so we don't cause an unobserved exception
}
// Always try to close async, if the websocket already closed
// then this will no-op
await handler.CloseAsync().PreserveCulture();
// Always try to close async, if the websocket already closed
// then this will no-op
await handler.CloseAsync().PreserveCulture();
// Cancel the token
cts.Cancel();
// Cancel the token
cts.Cancel();
});
}

private class OwinWebSocket : WebSocket
Expand Down

0 comments on commit c213737

Please sign in to comment.