Skip to content

Commit ad382ca

Browse files
authored
System.Net.Http.WinHttpHandler.StartRequestAsync assertion failed (#109799)
* System.Net.Http.WinHttpHandler.StartRequestAsync assertion failed * fix remarks
1 parent d8a6117 commit ad382ca

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private Func<
9090
private int _maxResponseDrainSize = HttpHandlerDefaults.DefaultMaxResponseDrainSize;
9191
private IDictionary<string, object>? _properties; // Only create dictionary when required.
9292
private volatile bool _operationStarted;
93-
private volatile bool _disposed;
93+
private volatile int _disposed;
9494
private SafeWinHttpHandle? _sessionHandle;
9595
private readonly WinHttpAuthHelper _authHelper = new WinHttpAuthHelper();
9696

@@ -539,13 +539,11 @@ public bool EnableMultipleHttp2Connections
539539

540540
protected override void Dispose(bool disposing)
541541
{
542-
if (!_disposed)
542+
if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0)
543543
{
544-
_disposed = true;
545-
546544
if (disposing && _sessionHandle != null)
547545
{
548-
SafeWinHttpHandle.DisposeAndClearHandle(ref _sessionHandle);
546+
_sessionHandle.Dispose();
549547
}
550548
}
551549

@@ -1033,7 +1031,7 @@ private async Task StartRequestAsync(WinHttpRequestState state)
10331031
}
10341032
finally
10351033
{
1036-
SafeWinHttpHandle.DisposeAndClearHandle(ref connectHandle);
1034+
connectHandle?.Dispose();
10371035

10381036
try
10391037
{
@@ -1620,7 +1618,7 @@ private void SetOperationStarted()
16201618

16211619
private void CheckDisposed()
16221620
{
1623-
if (_disposed)
1621+
if (_disposed == 1)
16241622
{
16251623
throw new ObjectDisposedException(GetType().FullName);
16261624
}

0 commit comments

Comments
 (0)