Skip to content

Commit c1d9659

Browse files
amcaseyvseanreesermsft
authored andcommitted
Address PR feedback
1 parent 6c6d304 commit c1d9659

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,22 @@ internal sealed partial class Http2Connection : IHttp2StreamLifetimeHandler, IHt
4848

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

51-
private static readonly int _enhanceYourCalmMaximumCount = AppContext.GetData(EnhanceYourCalmMaximumCountProperty) is int eycMaxCount
52-
? eycMaxCount
53-
: 10;
51+
private static readonly int _enhanceYourCalmMaximumCount = GetEnhanceYourCalmMaximumCount();
52+
53+
private static int GetEnhanceYourCalmMaximumCount()
54+
{
55+
var data = AppContext.GetData(EnhanceYourCalmMaximumCountProperty);
56+
if (data is int count)
57+
{
58+
return count;
59+
}
60+
if (data is string countStr && int.TryParse(countStr, out var parsed))
61+
{
62+
return parsed;
63+
}
64+
65+
return 20; // Empirically derived
66+
}
5467

5568
// Accumulate _enhanceYourCalmCount over the course of EnhanceYourCalmTickWindowCount ticks.
5669
// This should make bursts less likely to trigger disconnects.

src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ internal sealed class Http2FrameWriter
4343

4444
private readonly int _maximumFlowControlQueueSize;
4545

46+
private bool IsMaximumFlowControlQueueSizeEnabled => _maximumFlowControlQueueSize > 0;
47+
4648
private readonly object _writeLock = new object();
4749
private readonly Http2Frame _outgoingFrame;
4850
private readonly Http2HeadersEnumerator _headersEnumerator = new Http2HeadersEnumerator();
@@ -106,7 +108,7 @@ public Http2FrameWriter(
106108
? 4 * maxStreamsPerConnection
107109
: (int)ConfiguredMaximumFlowControlQueueSize;
108110

109-
if (_maximumFlowControlQueueSize < maxStreamsPerConnection)
111+
if (IsMaximumFlowControlQueueSizeEnabled && _maximumFlowControlQueueSize < maxStreamsPerConnection)
110112
{
111113
_log.Http2FlowControlQueueMaximumTooLow(_connectionContext.ConnectionId, maxStreamsPerConnection, _maximumFlowControlQueueSize);
112114
_maximumFlowControlQueueSize = maxStreamsPerConnection;
@@ -977,7 +979,7 @@ private void EnqueueWaitingForMoreConnectionWindow(Http2OutputProducer producer)
977979
_waitingForMoreConnectionWindow.Enqueue(producer);
978980
// This is re-entrant because abort will cause a final enqueue.
979981
// Easier to check for that condition than to make each enqueuer reason about what to call.
980-
if (!_aborted && _maximumFlowControlQueueSize > 0 && _waitingForMoreConnectionWindow.Count > _maximumFlowControlQueueSize)
982+
if (!_aborted && IsMaximumFlowControlQueueSizeEnabled && _waitingForMoreConnectionWindow.Count > _maximumFlowControlQueueSize)
981983
{
982984
_log.Http2FlowControlQueueOperationsExceeded(_connectionId, _maximumFlowControlQueueSize);
983985
_http2Connection.Abort(new ConnectionAbortedException("HTTP/2 connection exceeded the outgoing flow control maximum queue size."));

src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelTrace.Http2.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ private static partial class Http2Log
146146

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

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

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

155-
[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")]
155+
[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")]
156156
public static partial void Http2FlowControlQueueMaximumTooLow(ILogger logger, string connectionId, int expected, int actual);
157157
}
158158
}

0 commit comments

Comments
 (0)