Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
wtgodbe committed Oct 18, 2023
2 parents d9d432e + 57512b4 commit 3509fd7
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 32 deletions.
14 changes: 14 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
<clear />
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
<!-- Begin: Package sources from dotnet-efcore -->
<<<<<<< HEAD
<add key="darc-int-dotnet-efcore-f16e454" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-efcore-f16e454a/nuget/v3/index.json" />
<!-- End: Package sources from dotnet-efcore -->
<!-- Begin: Package sources from dotnet-runtime -->
<add key="darc-int-dotnet-runtime-3bcb9f2" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-runtime-3bcb9f24/nuget/v3/index.json" />
=======
<add key="darc-int-dotnet-efcore-c20ecc7" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-efcore-c20ecc79/nuget/v3/index.json" />
<!-- End: Package sources from dotnet-efcore -->
<!-- Begin: Package sources from dotnet-runtime -->
<add key="darc-int-dotnet-runtime-4a824ef" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-runtime-4a824ef3/nuget/v3/index.json" />
>>>>>>> v7.0.12
<!-- End: Package sources from dotnet-runtime -->
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
Expand All @@ -26,10 +33,17 @@
<clear />
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
<!-- Begin: Package sources from dotnet-efcore -->
<<<<<<< HEAD
<add key="darc-int-dotnet-efcore-f16e454" value="true" />
<!-- End: Package sources from dotnet-efcore -->
<!-- Begin: Package sources from dotnet-runtime -->
<add key="darc-int-dotnet-runtime-3bcb9f2" value="true" />
=======
<add key="darc-int-dotnet-efcore-c20ecc7" value="true" />
<!-- End: Package sources from dotnet-efcore -->
<!-- Begin: Package sources from dotnet-runtime -->
<add key="darc-int-dotnet-runtime-4a824ef" value="true" />
>>>>>>> v7.0.12
<!-- End: Package sources from dotnet-runtime -->
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
</disabledPackageSources>
Expand Down
36 changes: 18 additions & 18 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@
<ProductDependencies>
<Dependency Name="dotnet-ef" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.EntityFrameworkCore.Relational" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.EntityFrameworkCore.Tools" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.EntityFrameworkCore" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
<Sha>f16e454a752548577728fda7a7b20a8ad7405f36</Sha>
<Sha>c20ecc79b7df3657e186ac52e7fc050beea36c92</Sha>
</Dependency>
<Dependency Name="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
Expand Down Expand Up @@ -177,9 +177,9 @@
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>d099f075e45d2aa6007a22b71b45a08758559f80</Sha>
</Dependency>
<Dependency Name="Microsoft.Internal.Runtime.AspNetCore.Transport" Version="7.0.12-servicing.23463.5">
<Dependency Name="Microsoft.Internal.Runtime.AspNetCore.Transport" Version="7.0.12-servicing.23477.20">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3bcb9f24805914a1a73d9b4ef0c82b28ede106b4</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="7.0.0-alpha.1.22505.1">
<Uri>https://github.com/dotnet/source-build-externals</Uri>
Expand Down Expand Up @@ -256,39 +256,39 @@
</Dependency>
<Dependency Name="System.Threading.RateLimiting" Version="7.0.1">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>ecb34f85ec92e1b3c814edf7da83337e199e7f66</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<Dependency Name="Microsoft.Extensions.DependencyModel" Version="7.0.0">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>d099f075e45d2aa6007a22b71b45a08758559f80</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Ref" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3bcb9f24805914a1a73d9b4ef0c82b28ede106b4</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Runtime.MonoAOTCompiler.Task" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3bcb9f24805914a1a73d9b4ef0c82b28ede106b4</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Runtime.WebAssembly.Sdk" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3bcb9f24805914a1a73d9b4ef0c82b28ede106b4</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<!--
Win-x64 is used here because we have picked an arbitrary runtime identifier to flow the version of the latest NETCore.App runtime.
All Runtime.$rid packages should have the same version.
-->
<Dependency Name="Microsoft.NETCore.App.Runtime.win-x64" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3bcb9f24805914a1a73d9b4ef0c82b28ede106b4</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.browser-wasm" Version="7.0.12">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3bcb9f24805914a1a73d9b4ef0c82b28ede106b4</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="7.0.12-servicing.23463.5">
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="7.0.12-servicing.23477.20">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3bcb9f24805914a1a73d9b4ef0c82b28ede106b4</Sha>
<Sha>4a824ef37caa51072221584c64cbf15455f406ca</Sha>
</Dependency>
<Dependency Name="Microsoft.Web.Xdt" Version="7.0.0-preview.22423.2">
<Uri>https://github.com/dotnet/xdt</Uri>
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>7.0.12</MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>
<MicrosoftNETRuntimeWebAssemblySdkVersion>7.0.12</MicrosoftNETRuntimeWebAssemblySdkVersion>
<MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>7.0.12</MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>
<MicrosoftNETCoreBrowserDebugHostTransportVersion>7.0.12-servicing.23463.5</MicrosoftNETCoreBrowserDebugHostTransportVersion>
<MicrosoftNETCoreBrowserDebugHostTransportVersion>7.0.12-servicing.23477.20</MicrosoftNETCoreBrowserDebugHostTransportVersion>
<MicrosoftExtensionsCachingAbstractionsVersion>7.0.0</MicrosoftExtensionsCachingAbstractionsVersion>
<MicrosoftExtensionsCachingMemoryVersion>7.0.0</MicrosoftExtensionsCachingMemoryVersion>
<MicrosoftExtensionsConfigurationAbstractionsVersion>7.0.0</MicrosoftExtensionsConfigurationAbstractionsVersion>
Expand Down Expand Up @@ -103,7 +103,7 @@
<MicrosoftExtensionsOptionsDataAnnotationsVersion>7.0.0</MicrosoftExtensionsOptionsDataAnnotationsVersion>
<MicrosoftExtensionsOptionsVersion>7.0.1</MicrosoftExtensionsOptionsVersion>
<MicrosoftExtensionsPrimitivesVersion>7.0.0</MicrosoftExtensionsPrimitivesVersion>
<MicrosoftInternalRuntimeAspNetCoreTransportVersion>7.0.12-servicing.23463.5</MicrosoftInternalRuntimeAspNetCoreTransportVersion>
<MicrosoftInternalRuntimeAspNetCoreTransportVersion>7.0.12-servicing.23477.20</MicrosoftInternalRuntimeAspNetCoreTransportVersion>
<SystemConfigurationConfigurationManagerVersion>7.0.0</SystemConfigurationConfigurationManagerVersion>
<SystemDiagnosticsDiagnosticSourceVersion>7.0.2</SystemDiagnosticsDiagnosticSourceVersion>
<SystemDiagnosticsEventLogVersion>7.0.0</SystemDiagnosticsEventLogVersion>
Expand Down
67 changes: 61 additions & 6 deletions src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ internal sealed partial class Http2Connection : IHttp2StreamLifetimeHandler, IHt
private const int MaxStreamPoolSize = 100;
private const long StreamPoolExpiryTicks = TimeSpan.TicksPerSecond * 5;

private const string MaximumEnhanceYourCalmCountProperty = "Microsoft.AspNetCore.Server.Kestrel.Http2.MaxEnhanceYourCalmCount";

private static readonly int _enhanceYourCalmMaximumCount = GetMaximumEnhanceYourCalmCount();

private static int GetMaximumEnhanceYourCalmCount()
{
var data = AppContext.GetData(MaximumEnhanceYourCalmCountProperty);
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.
private const int EnhanceYourCalmTickWindowCount = 5;

private static bool IsEnhanceYourCalmEnabled => _enhanceYourCalmMaximumCount > 0;

private readonly HttpConnectionContext _context;
private readonly Http2FrameWriter _frameWriter;
private readonly Pipe _input;
Expand Down Expand Up @@ -74,6 +99,9 @@ internal sealed partial class Http2Connection : IHttp2StreamLifetimeHandler, IHt
private int _clientActiveStreamCount;
private int _serverActiveStreamCount;

private int _enhanceYourCalmCount;
private int _tickCount;

// The following are the only fields that can be modified outside of the ProcessRequestsAsync loop.
private readonly ConcurrentQueue<Http2Stream> _completedStreams = new ConcurrentQueue<Http2Stream>();
private readonly StreamCloseAwaitable _streamCompletionAwaitable = new StreamCloseAwaitable();
Expand Down Expand Up @@ -361,13 +389,20 @@ public async Task ProcessRequestsAsync<TContext>(IHttpApplication<TContext> appl
stream.Abort(new IOException(CoreStrings.Http2StreamAborted, connectionError));
}

// Use the server _serverActiveStreamCount to drain all requests on the server side.
// Can't use _clientActiveStreamCount now as we now decrement that count earlier/
// Can't use _streams.Count as we wait for RST/END_STREAM before removing the stream from the dictionary
while (_serverActiveStreamCount > 0)
// For some reason, this loop doesn't terminate when we're trying to abort.
// Since we're making a narrow fix for a patch, we'll bypass it in such scenarios.
// TODO: This is probably a bug - something in here should probably detect aborted
// connections and short-circuit.
if (!IsEnhanceYourCalmEnabled || error is not Http2ConnectionErrorException)
{
await _streamCompletionAwaitable;
UpdateCompletedStreams();
// Use the server _serverActiveStreamCount to drain all requests on the server side.
// Can't use _clientActiveStreamCount now as we now decrement that count earlier/
// Can't use _streams.Count as we wait for RST/END_STREAM before removing the stream from the dictionary
while (_serverActiveStreamCount > 0)
{
await _streamCompletionAwaitable;
UpdateCompletedStreams();
}
}

while (StreamPool.TryPop(out var pooledStream))
Expand Down Expand Up @@ -1170,6 +1205,20 @@ private void StartStream()
// Server is getting hit hard with connection resets.
// Tell client to calm down.
// TODO consider making when to send ENHANCE_YOUR_CALM configurable?

if (IsEnhanceYourCalmEnabled && Interlocked.Increment(ref _enhanceYourCalmCount) > EnhanceYourCalmTickWindowCount * _enhanceYourCalmMaximumCount)
{
Log.Http2TooManyEnhanceYourCalms(_context.ConnectionId, _enhanceYourCalmMaximumCount);

// Now that we've logged a useful message, we can put vague text in the exception
// messages in case they somehow make it back to the client (not expected)

// This will close the socket - we want to do that right away
Abort(new ConnectionAbortedException(CoreStrings.Http2ConnectionFaulted));
// Throwing an exception as well will help us clean up on our end more quickly by (e.g.) skipping processing of already-buffered input
throw new Http2ConnectionErrorException(CoreStrings.Http2ConnectionFaulted, Http2ErrorCode.ENHANCE_YOUR_CALM);
}

throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2TellClientToCalmDown, Http2ErrorCode.ENHANCE_YOUR_CALM);
}
}
Expand Down Expand Up @@ -1241,6 +1290,12 @@ private void AbortStream(int streamId, IOException error)
void IRequestProcessor.Tick(DateTimeOffset now)
{
Input.CancelPendingRead();
// We count EYCs over a window of a given length to avoid flagging short-lived bursts.
// At the end of each window, reset the count.
if (IsEnhanceYourCalmEnabled && ++_tickCount % EnhanceYourCalmTickWindowCount == 0)
{
Interlocked.Exchange(ref _enhanceYourCalmCount, 0);
}
}

void IHttp2StreamLifetimeHandler.OnStreamCompleted(Http2Stream stream)
Expand Down
Loading

0 comments on commit 3509fd7

Please sign in to comment.