Skip to content

Commit

Permalink
Remove synchronization from Http2Connection.ExtendWindow (#97878)
Browse files Browse the repository at this point in the history
_pendingWindowUpdate is the only state the ExtendWindow method touches under the lock. There is no other code that reads or writes _pendingWindowUpdate after the creation of the connection object. Originating from ProcessIncomingFramesAsync, calls to ExtendWindow are sequential, and never expected to happen concurrently.
  • Loading branch information
antonfirsov authored Feb 14, 2024
1 parent 99a16f6 commit 13e63af
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1771,23 +1771,18 @@ private bool ExtendWindow(int amount)
{
if (NetEventSource.Log.IsEnabled()) Trace($"{nameof(amount)}={amount}");
Debug.Assert(amount > 0);
Debug.Assert(_pendingWindowUpdate < ConnectionWindowThreshold);

int windowUpdateSize;
lock (SyncObject)
_pendingWindowUpdate += amount;
if (_pendingWindowUpdate < ConnectionWindowThreshold)
{
Debug.Assert(_pendingWindowUpdate < ConnectionWindowThreshold);

_pendingWindowUpdate += amount;
if (_pendingWindowUpdate < ConnectionWindowThreshold)
{
if (NetEventSource.Log.IsEnabled()) Trace($"{nameof(_pendingWindowUpdate)} {_pendingWindowUpdate} < {ConnectionWindowThreshold}.");
return false;
}

windowUpdateSize = _pendingWindowUpdate;
_pendingWindowUpdate = 0;
if (NetEventSource.Log.IsEnabled()) Trace($"{nameof(_pendingWindowUpdate)} {_pendingWindowUpdate} < {ConnectionWindowThreshold}.");
return false;
}

int windowUpdateSize = _pendingWindowUpdate;
_pendingWindowUpdate = 0;

LogExceptions(SendWindowUpdateAsync(0, windowUpdateSize));
return true;
}
Expand Down

0 comments on commit 13e63af

Please sign in to comment.