Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fb
  • Loading branch information
christothes committed Jun 24, 2025
commit 1cf836b06d7a5b3e715de7ad72c2f930d1d4e5b6
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ internal partial class AsyncWebsocketMessageResultEnumerator : IAsyncEnumerator<
public ClientResult Current { get; private set; }
private readonly CancellationToken _cancellationToken;
private readonly WebSocket _webSocket;
private readonly byte[] _receiveBuffer;
private bool _disposed = false;
private byte[] _receiveBuffer;

public AsyncWebsocketMessageResultEnumerator(WebSocket webSocket, CancellationToken cancellationToken)
{
Expand All @@ -27,12 +26,11 @@ public AsyncWebsocketMessageResultEnumerator(WebSocket webSocket, CancellationTo

public ValueTask DisposeAsync()
{
if (!_disposed)
if (Interlocked.Exchange(ref _receiveBuffer, null) is byte[] toReturn)
{
ArrayPool<byte>.Shared.Return(_receiveBuffer);
_webSocket?.Dispose();
_disposed = true;
ArrayPool<byte>.Shared.Return(toReturn);
}
_webSocket?.Dispose();
return new ValueTask(Task.CompletedTask);
}

Expand Down