Skip to content

Fix double dispose of GCHandle in BrowserWebSocket #113464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2025
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private async Task SendAsyncCore(ArraySegment<byte> buffer, WebSocketMessageType

if (sendTask != null) // this is optimization for single-threaded build, see resolvedPromise() in web-socket.ts. Null means synchronously resolved.
{
await CancellationHelper(sendTask, cancellationToken, previousState, pinBuffer).ConfigureAwait(false);
await CancellationHelper(sendTask, cancellationToken, previousState).ConfigureAwait(false);
}
}
catch (JSException ex)
Expand Down Expand Up @@ -442,7 +442,7 @@ private async Task<WebSocketReceiveResult> ReceiveAsyncCore(ArraySegment<byte> b

if (receiveTask != null) // this is optimization for single-threaded build, see resolvedPromise() in web-socket.ts. Null means synchronously resolved.
{
await CancellationHelper(receiveTask, cancellationToken, previousState, pinBuffer).ConfigureAwait(false);
await CancellationHelper(receiveTask, cancellationToken, previousState).ConfigureAwait(false);
}

return ConvertResponse();
Expand Down Expand Up @@ -550,13 +550,12 @@ private async Task CloseAsyncCore(WebSocketCloseStatus closeStatus, string? stat
}
}

private async Task CancellationHelper(Task promise, CancellationToken cancellationToken, WebSocketState previousState, IDisposable? disposable = null)
private async Task CancellationHelper(Task promise, CancellationToken cancellationToken, WebSocketState previousState)
{
try
{
if (promise.IsCompletedSuccessfully)
{
disposable?.Dispose();
return;
}
if (promise.IsCompleted)
Expand Down Expand Up @@ -602,10 +601,6 @@ private async Task CancellationHelper(Task promise, CancellationToken cancellati
throw new WebSocketException(WebSocketError.NativeError, ex);
}
}
finally
{
disposable?.Dispose();
}
}

// needs to be called with locked _lockObject
Expand Down
Loading