Skip to content
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

System.Net.Http.WinHttpHandler.StartRequestAsync assertion failed #109799

Merged
merged 3 commits into from
Feb 3, 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 @@ -90,7 +90,7 @@ private Func<
private int _maxResponseDrainSize = HttpHandlerDefaults.DefaultMaxResponseDrainSize;
private IDictionary<string, object>? _properties; // Only create dictionary when required.
private volatile bool _operationStarted;
private volatile bool _disposed;
private volatile int _disposed;
private SafeWinHttpHandle? _sessionHandle;
private readonly WinHttpAuthHelper _authHelper = new WinHttpAuthHelper();

Expand Down Expand Up @@ -539,13 +539,11 @@ public bool EnableMultipleHttp2Connections

protected override void Dispose(bool disposing)
{
if (!_disposed)
if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0)
{
_disposed = true;

if (disposing && _sessionHandle != null)
{
SafeWinHttpHandle.DisposeAndClearHandle(ref _sessionHandle);
_sessionHandle.Dispose();
}
}

Expand Down Expand Up @@ -1033,7 +1031,7 @@ private async Task StartRequestAsync(WinHttpRequestState state)
}
finally
{
SafeWinHttpHandle.DisposeAndClearHandle(ref connectHandle);
connectHandle?.Dispose();

try
{
Expand Down Expand Up @@ -1620,7 +1618,7 @@ private void SetOperationStarted()

private void CheckDisposed()
{
if (_disposed)
if (_disposed == 1)
{
throw new ObjectDisposedException(GetType().FullName);
}
Expand Down
Loading