Skip to content

Commit 2ae5cc0

Browse files
Merge commit '5a4c82ec57fadddef9ce841d608de5c7c8c74446' into internal-merge-7.0-2023-08-08-1043
2 parents 45889db + 5a4c82e commit 2ae5cc0

23 files changed

+623
-121
lines changed

NuGet.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
<clear />
55
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
66
<!-- Begin: Package sources from dotnet-efcore -->
7+
<add key="darc-int-dotnet-efcore-8907538" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-efcore-8907538f/nuget/v3/index.json" />
78
<!-- End: Package sources from dotnet-efcore -->
89
<!-- Begin: Package sources from dotnet-runtime -->
10+
<add key="darc-int-dotnet-runtime-a6dbb80" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-runtime-a6dbb800/nuget/v3/index.json" />
911
<!-- End: Package sources from dotnet-runtime -->
1012
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
1113
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
@@ -24,8 +26,10 @@
2426
<clear />
2527
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
2628
<!-- Begin: Package sources from dotnet-efcore -->
29+
<add key="darc-int-dotnet-efcore-8907538" value="true" />
2730
<!-- End: Package sources from dotnet-efcore -->
2831
<!-- Begin: Package sources from dotnet-runtime -->
32+
<add key="darc-int-dotnet-runtime-a6dbb80" value="true" />
2933
<!-- End: Package sources from dotnet-runtime -->
3034
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
3135
</disabledPackageSources>

eng/Version.Details.xml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@
99
-->
1010
<Dependencies>
1111
<ProductDependencies>
12-
<Dependency Name="dotnet-ef" Version="7.0.9">
12+
<Dependency Name="dotnet-ef" Version="7.0.10">
1313
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
14-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
14+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
1515
</Dependency>
16-
<Dependency Name="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9">
16+
<Dependency Name="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.10">
1717
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
18-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
18+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
1919
</Dependency>
20-
<Dependency Name="Microsoft.EntityFrameworkCore.Relational" Version="7.0.9">
20+
<Dependency Name="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10">
2121
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
22-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
22+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
2323
</Dependency>
24-
<Dependency Name="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.9">
24+
<Dependency Name="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10">
2525
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
26-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
26+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
2727
</Dependency>
28-
<Dependency Name="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9">
28+
<Dependency Name="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10">
2929
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
30-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
30+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
3131
</Dependency>
32-
<Dependency Name="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
32+
<Dependency Name="Microsoft.EntityFrameworkCore.Tools" Version="7.0.10">
3333
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
34-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
34+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
3535
</Dependency>
36-
<Dependency Name="Microsoft.EntityFrameworkCore" Version="7.0.9">
36+
<Dependency Name="Microsoft.EntityFrameworkCore" Version="7.0.10">
3737
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
38-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
38+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
3939
</Dependency>
40-
<Dependency Name="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
40+
<Dependency Name="Microsoft.EntityFrameworkCore.Design" Version="7.0.10">
4141
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-efcore</Uri>
42-
<Sha>e00be013488a9a56a0e29230be0fe10026dbb209</Sha>
42+
<Sha>8907538f3d4da2fffdb0516f05542802585757e6</Sha>
4343
</Dependency>
4444
<Dependency Name="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0">
4545
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
@@ -177,9 +177,9 @@
177177
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
178178
<Sha>d099f075e45d2aa6007a22b71b45a08758559f80</Sha>
179179
</Dependency>
180-
<Dependency Name="Microsoft.Internal.Runtime.AspNetCore.Transport" Version="7.0.9-servicing.23320.18">
180+
<Dependency Name="Microsoft.Internal.Runtime.AspNetCore.Transport" Version="7.0.10-servicing.23363.12">
181181
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
182-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
182+
<Sha>a6dbb800a47735bde43187350fd3aff4071c7f9c</Sha>
183183
</Dependency>
184184
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="7.0.0-alpha.1.22505.1">
185185
<Uri>https://github.com/dotnet/source-build-externals</Uri>
@@ -262,33 +262,33 @@
262262
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
263263
<Sha>d099f075e45d2aa6007a22b71b45a08758559f80</Sha>
264264
</Dependency>
265-
<Dependency Name="Microsoft.NETCore.App.Ref" Version="7.0.9">
265+
<Dependency Name="Microsoft.NETCore.App.Ref" Version="7.0.10">
266266
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
267-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
267+
<Sha>a6dbb800a47735bde43187350fd3aff4071c7f9c</Sha>
268268
</Dependency>
269-
<Dependency Name="Microsoft.NET.Runtime.MonoAOTCompiler.Task" Version="7.0.9">
269+
<Dependency Name="Microsoft.NET.Runtime.MonoAOTCompiler.Task" Version="7.0.10">
270270
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
271-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
271+
<Sha>a6dbb800a47735bde43187350fd3aff4071c7f9c</Sha>
272272
</Dependency>
273-
<Dependency Name="Microsoft.NET.Runtime.WebAssembly.Sdk" Version="7.0.9">
273+
<Dependency Name="Microsoft.NET.Runtime.WebAssembly.Sdk" Version="7.0.10">
274274
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
275-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
275+
<Sha>a6dbb800a47735bde43187350fd3aff4071c7f9c</Sha>
276276
</Dependency>
277277
<!--
278278
Win-x64 is used here because we have picked an arbitrary runtime identifier to flow the version of the latest NETCore.App runtime.
279279
All Runtime.$rid packages should have the same version.
280280
-->
281-
<Dependency Name="Microsoft.NETCore.App.Runtime.win-x64" Version="7.0.9">
281+
<Dependency Name="Microsoft.NETCore.App.Runtime.win-x64" Version="7.0.10">
282282
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
283-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
283+
<Sha>a6dbb800a47735bde43187350fd3aff4071c7f9c</Sha>
284284
</Dependency>
285-
<Dependency Name="Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.browser-wasm" Version="7.0.9">
285+
<Dependency Name="Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.browser-wasm" Version="7.0.10">
286286
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
287-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
287+
<Sha>a6dbb800a47735bde43187350fd3aff4071c7f9c</Sha>
288288
</Dependency>
289-
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="7.0.9-servicing.23320.18">
289+
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="7.0.10-servicing.23363.12">
290290
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
291-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
291+
<Sha>a6dbb800a47735bde43187350fd3aff4071c7f9c</Sha>
292292
</Dependency>
293293
<Dependency Name="Microsoft.Web.Xdt" Version="7.0.0-preview.22423.2">
294294
<Uri>https://github.com/dotnet/xdt</Uri>
@@ -300,7 +300,7 @@
300300
<!-- Listed explicitly to workaround https://github.com/dotnet/cli/issues/10528 -->
301301
<Dependency Name="Microsoft.NETCore.Platforms" Version="7.0.4">
302302
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
303-
<Sha>8e9a17b2216f51a5788f8b1c467a4cf3b769e7d7</Sha>
303+
<Sha>8587d13a2764c025277d628471984bae8e16427c</Sha>
304304
</Dependency>
305305
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="7.0.0-beta.23361.2">
306306
<Uri>https://github.com/dotnet/arcade</Uri>

eng/Versions.props

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@
6363
<PropertyGroup Label="Automated">
6464
<!-- Packages from dotnet/runtime -->
6565
<MicrosoftExtensionsDependencyModelVersion>7.0.0</MicrosoftExtensionsDependencyModelVersion>
66-
<MicrosoftNETCoreAppRefVersion>7.0.9</MicrosoftNETCoreAppRefVersion>
67-
<MicrosoftNETCoreAppRuntimewinx64Version>7.0.9</MicrosoftNETCoreAppRuntimewinx64Version>
68-
<MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>7.0.9</MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>
69-
<MicrosoftNETRuntimeWebAssemblySdkVersion>7.0.9</MicrosoftNETRuntimeWebAssemblySdkVersion>
70-
<MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>7.0.9</MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>
71-
<MicrosoftNETCoreBrowserDebugHostTransportVersion>7.0.9-servicing.23320.18</MicrosoftNETCoreBrowserDebugHostTransportVersion>
66+
<MicrosoftNETCoreAppRefVersion>7.0.10</MicrosoftNETCoreAppRefVersion>
67+
<MicrosoftNETCoreAppRuntimewinx64Version>7.0.10</MicrosoftNETCoreAppRuntimewinx64Version>
68+
<MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>7.0.10</MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>
69+
<MicrosoftNETRuntimeWebAssemblySdkVersion>7.0.10</MicrosoftNETRuntimeWebAssemblySdkVersion>
70+
<MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>7.0.10</MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>
71+
<MicrosoftNETCoreBrowserDebugHostTransportVersion>7.0.10-servicing.23363.12</MicrosoftNETCoreBrowserDebugHostTransportVersion>
7272
<MicrosoftExtensionsCachingAbstractionsVersion>7.0.0</MicrosoftExtensionsCachingAbstractionsVersion>
7373
<MicrosoftExtensionsCachingMemoryVersion>7.0.0</MicrosoftExtensionsCachingMemoryVersion>
7474
<MicrosoftExtensionsConfigurationAbstractionsVersion>7.0.0</MicrosoftExtensionsConfigurationAbstractionsVersion>
@@ -103,7 +103,7 @@
103103
<MicrosoftExtensionsOptionsDataAnnotationsVersion>7.0.0</MicrosoftExtensionsOptionsDataAnnotationsVersion>
104104
<MicrosoftExtensionsOptionsVersion>7.0.1</MicrosoftExtensionsOptionsVersion>
105105
<MicrosoftExtensionsPrimitivesVersion>7.0.0</MicrosoftExtensionsPrimitivesVersion>
106-
<MicrosoftInternalRuntimeAspNetCoreTransportVersion>7.0.9-servicing.23320.18</MicrosoftInternalRuntimeAspNetCoreTransportVersion>
106+
<MicrosoftInternalRuntimeAspNetCoreTransportVersion>7.0.10-servicing.23363.12</MicrosoftInternalRuntimeAspNetCoreTransportVersion>
107107
<SystemConfigurationConfigurationManagerVersion>7.0.0</SystemConfigurationConfigurationManagerVersion>
108108
<SystemDiagnosticsDiagnosticSourceVersion>7.0.2</SystemDiagnosticsDiagnosticSourceVersion>
109109
<SystemDiagnosticsEventLogVersion>7.0.0</SystemDiagnosticsEventLogVersion>
@@ -125,14 +125,14 @@
125125
<!-- Only listed explicitly to workaround https://github.com/dotnet/cli/issues/10528 -->
126126
<MicrosoftNETCorePlatformsVersion>7.0.4</MicrosoftNETCorePlatformsVersion>
127127
<!-- Packages from dotnet/efcore -->
128-
<dotnetefVersion>7.0.9</dotnetefVersion>
129-
<MicrosoftEntityFrameworkCoreInMemoryVersion>7.0.9</MicrosoftEntityFrameworkCoreInMemoryVersion>
130-
<MicrosoftEntityFrameworkCoreRelationalVersion>7.0.9</MicrosoftEntityFrameworkCoreRelationalVersion>
131-
<MicrosoftEntityFrameworkCoreSqliteVersion>7.0.9</MicrosoftEntityFrameworkCoreSqliteVersion>
132-
<MicrosoftEntityFrameworkCoreSqlServerVersion>7.0.9</MicrosoftEntityFrameworkCoreSqlServerVersion>
133-
<MicrosoftEntityFrameworkCoreToolsVersion>7.0.9</MicrosoftEntityFrameworkCoreToolsVersion>
134-
<MicrosoftEntityFrameworkCoreVersion>7.0.9</MicrosoftEntityFrameworkCoreVersion>
135-
<MicrosoftEntityFrameworkCoreDesignVersion>7.0.9</MicrosoftEntityFrameworkCoreDesignVersion>
128+
<dotnetefVersion>7.0.10</dotnetefVersion>
129+
<MicrosoftEntityFrameworkCoreInMemoryVersion>7.0.10</MicrosoftEntityFrameworkCoreInMemoryVersion>
130+
<MicrosoftEntityFrameworkCoreRelationalVersion>7.0.10</MicrosoftEntityFrameworkCoreRelationalVersion>
131+
<MicrosoftEntityFrameworkCoreSqliteVersion>7.0.10</MicrosoftEntityFrameworkCoreSqliteVersion>
132+
<MicrosoftEntityFrameworkCoreSqlServerVersion>7.0.10</MicrosoftEntityFrameworkCoreSqlServerVersion>
133+
<MicrosoftEntityFrameworkCoreToolsVersion>7.0.10</MicrosoftEntityFrameworkCoreToolsVersion>
134+
<MicrosoftEntityFrameworkCoreVersion>7.0.10</MicrosoftEntityFrameworkCoreVersion>
135+
<MicrosoftEntityFrameworkCoreDesignVersion>7.0.10</MicrosoftEntityFrameworkCoreDesignVersion>
136136
<!-- Packages from dotnet/arcade -->
137137
<MicrosoftDotNetBuildTasksInstallersVersion>7.0.0-beta.23361.2</MicrosoftDotNetBuildTasksInstallersVersion>
138138
<MicrosoftDotNetBuildTasksTemplatingVersion>7.0.0-beta.23361.2</MicrosoftDotNetBuildTasksTemplatingVersion>

src/Servers/IIS/IIS/test/Common.LongTests/ShutdownTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,15 @@ public async Task ClosesConnectionOnServerAbortOutOfProcess()
535535
var response = await deploymentResult.HttpClient.GetAsync("/Abort").TimeoutAfter(TimeoutExtensions.DefaultTimeoutValue);
536536

537537
Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode);
538+
539+
#if NEWSHIM_FUNCTIONALS
540+
// In-proc SocketConnection isn't used and there's no abort
538541
// 0x80072f78 ERROR_HTTP_INVALID_SERVER_RESPONSE The server returned an invalid or unrecognized response
539542
Assert.Contains("0x80072f78", await response.Content.ReadAsStringAsync());
543+
#else
544+
// 0x80072efe ERROR_INTERNET_CONNECTION_ABORTED The connection with the server was terminated abnormally
545+
Assert.Contains("0x80072efe", await response.Content.ReadAsStringAsync());
546+
#endif
540547
}
541548
catch (HttpRequestException)
542549
{

src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ protected override void OnRequestProcessingEnded()
9898
_http1Output.Dispose();
9999
}
100100

101-
public void OnInputOrOutputCompleted()
101+
void IRequestProcessor.OnInputOrOutputCompleted()
102+
{
103+
// Closed gracefully.
104+
_http1Output.Abort(ServerOptions.FinOnError ? new ConnectionAbortedException(CoreStrings.ConnectionAbortedByClient) : null!);
105+
CancelRequestAbortedToken();
106+
}
107+
108+
void IHttpOutputAborter.OnInputOrOutputCompleted()
102109
{
103110
_http1Output.Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedByClient));
104111
CancelRequestAbortedToken();

src/Servers/Kestrel/Core/src/Internal/Http/Http1MessageBody.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected void ThrowUnexpectedEndOfRequestContent()
204204
// so we call OnInputOrOutputCompleted() now to prevent a race in our tests where a 400
205205
// response is written after observing the unexpected end of request content instead of just
206206
// closing the connection without a response as expected.
207-
_context.OnInputOrOutputCompleted();
207+
((IHttpOutputAborter)_context).OnInputOrOutputCompleted();
208208

209209
KestrelBadHttpRequestException.Throw(RequestRejectionReason.UnexpectedEndOfRequestContent);
210210
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public Http2Connection(HttpConnectionContext context)
159159
public void OnInputOrOutputCompleted()
160160
{
161161
TryClose();
162-
_frameWriter.Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedByClient));
162+
var useException = _context.ServiceContext.ServerOptions.FinOnError || _clientActiveStreamCount != 0;
163+
_frameWriter.Abort(useException ? new ConnectionAbortedException(CoreStrings.ConnectionAbortedByClient) : null!);
163164
}
164165

165166
public void Abort(ConnectionAbortedException ex)

src/Servers/Kestrel/Core/src/KestrelServerOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core;
2626
public class KestrelServerOptions
2727
{
2828
internal const string DisableHttp1LineFeedTerminatorsSwitchKey = "Microsoft.AspNetCore.Server.Kestrel.DisableHttp1LineFeedTerminators";
29+
private const string FinOnErrorSwitch = "Microsoft.AspNetCore.Server.Kestrel.FinOnError";
30+
private static readonly bool _finOnError;
31+
32+
static KestrelServerOptions()
33+
{
34+
AppContext.TryGetSwitch(FinOnErrorSwitch, out _finOnError);
35+
}
2936

3037
// internal to fast-path header decoding when RequestHeaderEncodingSelector is unchanged.
3138
internal static readonly Func<string, Encoding?> DefaultHeaderEncodingSelector = _ => null;
3239

40+
// Opt-out flag for back compat. Remove in 9.0 (or make public).
41+
internal bool FinOnError { get; set; } = _finOnError;
42+
3343
private Func<string, Encoding?> _requestHeaderEncodingSelector = DefaultHeaderEncodingSelector;
3444

3545
private Func<string, Encoding?> _responseHeaderEncodingSelector = DefaultHeaderEncodingSelector;

src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal sealed partial class SocketConnection : TransportConnection
3030
private readonly TaskCompletionSource _waitForConnectionClosedTcs = new TaskCompletionSource();
3131
private bool _connectionClosed;
3232
private readonly bool _waitForData;
33+
private readonly bool _finOnError;
3334

3435
internal SocketConnection(Socket socket,
3536
MemoryPool<byte> memoryPool,
@@ -38,7 +39,8 @@ internal SocketConnection(Socket socket,
3839
SocketSenderPool socketSenderPool,
3940
PipeOptions inputOptions,
4041
PipeOptions outputOptions,
41-
bool waitForData = true)
42+
bool waitForData = true,
43+
bool finOnError = false)
4244
{
4345
Debug.Assert(socket != null);
4446
Debug.Assert(memoryPool != null);
@@ -49,6 +51,7 @@ internal SocketConnection(Socket socket,
4951
_logger = logger;
5052
_waitForData = waitForData;
5153
_socketSenderPool = socketSenderPool;
54+
_finOnError = finOnError;
5255

5356
LocalEndPoint = _socket.LocalEndPoint;
5457
RemoteEndPoint = _socket.RemoteEndPoint;
@@ -380,11 +383,21 @@ private void Shutdown(Exception? shutdownReason)
380383
// ever observe the nondescript ConnectionAbortedException except for connection middleware attempting
381384
// to half close the connection which is currently unsupported.
382385
_shutdownReason = shutdownReason ?? new ConnectionAbortedException("The Socket transport's send loop completed gracefully.");
386+
387+
// NB: not _shutdownReason since we don't want to do this on graceful completion
388+
if (!_finOnError && shutdownReason is not null)
389+
{
390+
SocketsLog.ConnectionWriteRst(_logger, this, shutdownReason.Message);
391+
392+
// This forces an abortive close with linger time 0 (and implies Dispose)
393+
_socket.Close(timeout: 0);
394+
return;
395+
}
396+
383397
SocketsLog.ConnectionWriteFin(_logger, this, _shutdownReason.Message);
384398

385399
try
386400
{
387-
// Try to gracefully close the socket even for aborts to match libuv behavior.
388401
_socket.Shutdown(SocketShutdown.Both);
389402
}
390403
catch

src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketsLog.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public static void ConnectionWriteFin(ILogger logger, SocketConnection connectio
3131
}
3232
}
3333

34+
[LoggerMessage(8, LogLevel.Debug, @"Connection id ""{ConnectionId}"" sending RST because: ""{Reason}""", EventName = "ConnectionWriteRst", SkipEnabledCheck = true)]
35+
private static partial void ConnectionWriteRstCore(ILogger logger, string connectionId, string reason);
36+
37+
public static void ConnectionWriteRst(ILogger logger, SocketConnection connection, string reason)
38+
{
39+
if (logger.IsEnabled(LogLevel.Debug))
40+
{
41+
ConnectionWriteRstCore(logger, connection.ConnectionId, reason);
42+
}
43+
}
44+
3445
// Reserved: Event ID 11, EventName = ConnectionWrite
3546

3647
// Reserved: Event ID 12, EventName = ConnectionWriteCallback

0 commit comments

Comments
 (0)