Skip to content

Commit 857a178

Browse files
authored
Patch memory leak with subscriptions when client abruptly terminates (#668)
1 parent db8484f commit 857a178

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/Transports.Subscriptions.WebSockets/WebSocketReaderPipeline.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,28 @@ public void LinkTo(ITargetBlock<OperationMessage> target)
4242

4343
public async Task Complete(WebSocketCloseStatus closeStatus, string statusDescription)
4444
{
45-
if (_socket.State != WebSocketState.Closed &&
46-
_socket.State != WebSocketState.CloseSent &&
47-
_socket.State != WebSocketState.Aborted)
48-
try
45+
try
46+
{
47+
if (_socket.State != WebSocketState.Closed &&
48+
_socket.State != WebSocketState.CloseSent &&
49+
_socket.State != WebSocketState.Aborted)
4950
{
5051
if (closeStatus == WebSocketCloseStatus.NormalClosure)
5152
await _socket.CloseAsync(
52-
closeStatus,
53-
statusDescription,
54-
CancellationToken.None);
53+
closeStatus,
54+
statusDescription,
55+
CancellationToken.None);
5556
else
5657
await _socket.CloseOutputAsync(
57-
closeStatus,
58-
statusDescription,
59-
CancellationToken.None);
60-
}
61-
finally
62-
{
63-
_startBlock.Complete();
58+
closeStatus,
59+
statusDescription,
60+
CancellationToken.None);
6461
}
62+
}
63+
finally
64+
{
65+
_startBlock.Complete();
66+
}
6567
}
6668

6769
public Task Completion => _endBlock.Completion;

0 commit comments

Comments
 (0)