Skip to content

Commit ed6226f

Browse files
committed
Deadlock in WsSession/WebSocket #205
1 parent f233253 commit ed6226f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

source/NetCoreServer/WebSocket.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,20 +510,14 @@ public int RequiredReceiveFrameSize()
510510
/// </summary>
511511
public void ClearWsBuffers()
512512
{
513-
lock (WsSendLock)
514-
{
515-
WsSendBuffer.Clear();
516-
Array.Clear(WsSendMask, 0, WsSendMask.Length);
517-
}
518-
519-
// Sometimes on disconnect the receive lock could be taken by receive thread.
520-
// In this case we'll skip the receive buffer clearing. It will happen on
521-
// re-connect then or in GC.
522-
513+
// Clear the receive buffer
523514
bool acquiredReceiveLock = false;
524515

525516
try
526517
{
518+
// Sometimes on disconnect the receive lock could be taken by receive thread.
519+
// In this case we'll skip the receive buffer clearing. It will happen on
520+
// re-connect then or in GC.
527521
Monitor.TryEnter(WsReceiveLock, ref acquiredReceiveLock);
528522
if (acquiredReceiveLock)
529523
{
@@ -541,6 +535,13 @@ public void ClearWsBuffers()
541535
if (acquiredReceiveLock)
542536
Monitor.Exit(WsReceiveLock);
543537
}
538+
539+
// Clear the send buffer
540+
lock (WsSendLock)
541+
{
542+
WsSendBuffer.Clear();
543+
Array.Clear(WsSendMask, 0, WsSendMask.Length);
544+
}
544545
}
545546

546547
/// <summary>

0 commit comments

Comments
 (0)