Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
amcasey authored and vseanreesermsft committed Sep 27, 2023
1 parent 6c6d304 commit c1d9659
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
19 changes: 16 additions & 3 deletions src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,22 @@ internal sealed partial class Http2Connection : IHttp2StreamLifetimeHandler, IHt

private const string EnhanceYourCalmMaximumCountProperty = "Microsoft.AspNetCore.Server.Kestrel.Http2.EnhanceYourCalmCount";

private static readonly int _enhanceYourCalmMaximumCount = AppContext.GetData(EnhanceYourCalmMaximumCountProperty) is int eycMaxCount
? eycMaxCount
: 10;
private static readonly int _enhanceYourCalmMaximumCount = GetEnhanceYourCalmMaximumCount();

private static int GetEnhanceYourCalmMaximumCount()
{
var data = AppContext.GetData(EnhanceYourCalmMaximumCountProperty);
if (data is int count)
{
return count;
}
if (data is string countStr && int.TryParse(countStr, out var parsed))
{
return parsed;
}

return 20; // Empirically derived
}

// Accumulate _enhanceYourCalmCount over the course of EnhanceYourCalmTickWindowCount ticks.
// This should make bursts less likely to trigger disconnects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal sealed class Http2FrameWriter

private readonly int _maximumFlowControlQueueSize;

private bool IsMaximumFlowControlQueueSizeEnabled => _maximumFlowControlQueueSize > 0;

private readonly object _writeLock = new object();
private readonly Http2Frame _outgoingFrame;
private readonly Http2HeadersEnumerator _headersEnumerator = new Http2HeadersEnumerator();
Expand Down Expand Up @@ -106,7 +108,7 @@ public Http2FrameWriter(
? 4 * maxStreamsPerConnection
: (int)ConfiguredMaximumFlowControlQueueSize;

if (_maximumFlowControlQueueSize < maxStreamsPerConnection)
if (IsMaximumFlowControlQueueSizeEnabled && _maximumFlowControlQueueSize < maxStreamsPerConnection)
{
_log.Http2FlowControlQueueMaximumTooLow(_connectionContext.ConnectionId, maxStreamsPerConnection, _maximumFlowControlQueueSize);
_maximumFlowControlQueueSize = maxStreamsPerConnection;
Expand Down Expand Up @@ -977,7 +979,7 @@ private void EnqueueWaitingForMoreConnectionWindow(Http2OutputProducer producer)
_waitingForMoreConnectionWindow.Enqueue(producer);
// This is re-entrant because abort will cause a final enqueue.
// Easier to check for that condition than to make each enqueuer reason about what to call.
if (!_aborted && _maximumFlowControlQueueSize > 0 && _waitingForMoreConnectionWindow.Count > _maximumFlowControlQueueSize)
if (!_aborted && IsMaximumFlowControlQueueSizeEnabled && _waitingForMoreConnectionWindow.Count > _maximumFlowControlQueueSize)
{
_log.Http2FlowControlQueueOperationsExceeded(_connectionId, _maximumFlowControlQueueSize);
_http2Connection.Abort(new ConnectionAbortedException("HTTP/2 connection exceeded the outgoing flow control maximum queue size."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ private static partial class Http2Log

// Highest shared ID is 63. New consecutive IDs start at 64

[LoggerMessage(64, LogLevel.Error, @"Connection id ""{ConnectionId}"" aborted since at least ""{Count}"" ENHANCE_YOUR_CALM responses were required per second.", EventName = "Http2TooManyEnhanceYourCalms")]
[LoggerMessage(64, LogLevel.Debug, @"Connection id ""{ConnectionId}"" aborted since at least ""{Count}"" ENHANCE_YOUR_CALM responses were required per second.", EventName = "Http2TooManyEnhanceYourCalms")]
public static partial void Http2TooManyEnhanceYourCalms(ILogger logger, string connectionId, int count);

[LoggerMessage(65, LogLevel.Error, @"Connection id ""{ConnectionId}"" exceeded the output flow control maximum queue size of ""{Count}"".", EventName = "Http2FlowControlQueueOperationsExceeded")]
[LoggerMessage(65, LogLevel.Debug, @"Connection id ""{ConnectionId}"" exceeded the output flow control maximum queue size of ""{Count}"".", EventName = "Http2FlowControlQueueOperationsExceeded")]
public static partial void Http2FlowControlQueueOperationsExceeded(ILogger logger, string connectionId, int count);

[LoggerMessage(66, LogLevel.Trace, @"Connection id ""{ConnectionId}"" configured maximum flow control queue size ""{Actual}"" is less than the maximum streams per connection ""{Expected}"" - increasing to match.", EventName = "Http2FlowControlQueueMaximumTooLow")]
[LoggerMessage(66, LogLevel.Debug, @"Connection id ""{ConnectionId}"" configured maximum flow control queue size ""{Actual}"" is less than the maximum streams per connection ""{Expected}"" - increasing to match.", EventName = "Http2FlowControlQueueMaximumTooLow")]
public static partial void Http2FlowControlQueueMaximumTooLow(ILogger logger, string connectionId, int expected, int actual);
}
}

0 comments on commit c1d9659

Please sign in to comment.