Skip to content

Commit 5b6eefd

Browse files
authored
Merge pull request #201 from LykkeCity/wampv2
NetCore RPC memory leak fixed
2 parents 88bb816 + 6420cfc commit 5b6eefd

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/net45/Extensions/WampSharp.AspNetCore.WebSockets.Server/AspNetCoreWebSocketTransport.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,22 @@ private async Task WebSocketHandler(HttpContext context, Func<Task> next)
9595

9696
if (subprotocol != null)
9797
{
98-
WebSocket websocket =
99-
await context.WebSockets.
100-
AcceptWebSocketAsync(subprotocol)
101-
.ConfigureAwait(false);
98+
using (var websocket = await context.WebSockets.AcceptWebSocketAsync(subprotocol).ConfigureAwait(false))
99+
{
102100

103-
// In an ideal world, OnNewConnection would return the
104-
// connection itself and then we could somehow access its
105-
// task, but for now we wrap the WebSocket with a WebSocketData
106-
// struct, and let OnNewConnection to fill us magically
107-
// the ReadTask
108-
WebSocketData webSocketData = new WebSocketData(websocket, context);
101+
// In an ideal world, OnNewConnection would return the
102+
// connection itself and then we could somehow access its
103+
// task, but for now we wrap the WebSocket with a WebSocketData
104+
// struct, and let OnNewConnection to fill us magically
105+
// the ReadTask
106+
WebSocketData webSocketData = new WebSocketData(websocket, context);
109107

110-
OnNewConnection(webSocketData);
108+
OnNewConnection(webSocketData);
111109

112-
await webSocketData.ReadTask.ConfigureAwait(false);
110+
await webSocketData.ReadTask.ConfigureAwait(false);
113111

114-
return;
112+
return;
113+
}
115114
}
116115
}
117116

src/net45/WampSharp/WAMP2/V2/Rpc/Dealer/WampClientRouterCallbackAdapter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public WampClientRouterCallbackAdapter(IWampRawRpcOperationClientCallback caller
2222

2323
private void OnDisconnected(object sender, EventArgs e)
2424
{
25+
mNotifier.Disconnected -= OnDisconnected;
2526
RaiseDisconnected();
2627
}
2728

src/net45/WampSharp/WAMP2/V2/Rpc/Dealer/WampRpcOperationCallback.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void Error<TResult>(IWampFormatter<TResult> formatter, TResult details, s
6161

6262
private void OnConnectionClosed(object sender, EventArgs e)
6363
{
64+
mMonitor.ConnectionClosed -= OnConnectionClosed;
6465
RaiseDisconnected();
6566
}
6667

0 commit comments

Comments
 (0)