Skip to content

Commit 2ec2536

Browse files
authored
HTTP/3: Avoid ConnectionAbortedException allocations (#42708)
1 parent dfd7473 commit 2ec2536

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,6 @@ public async Task ProcessRequestAsync<TContext>(IHttpApplication<TContext> appli
637637
}
638638
finally
639639
{
640-
var streamError = error as ConnectionAbortedException
641-
?? new ConnectionAbortedException("The stream has completed.", error!);
642-
643640
await Input.CompleteAsync();
644641

645642
// Once the header is finished being received then the app has started.
@@ -692,6 +689,9 @@ public async Task ProcessRequestAsync<TContext>(IHttpApplication<TContext> appli
692689
}
693690
catch
694691
{
692+
var streamError = error as ConnectionAbortedException
693+
?? new ConnectionAbortedException("The stream has completed.", error!);
694+
695695
Abort(streamError, Http3ErrorCode.ProtocolError);
696696
throw;
697697
}

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal;
1414

1515
internal partial class QuicStreamContext : TransportConnection, IPooledStream, IDisposable
1616
{
17+
private static readonly ConnectionAbortedException SendGracefullyCompletedException = new ConnectionAbortedException("The QUIC transport's send loop completed gracefully.");
18+
1719
// Internal for testing.
1820
internal Task _processingTask = Task.CompletedTask;
1921

@@ -499,8 +501,7 @@ private void ShutdownWrite(Exception? shutdownReason)
499501
{
500502
lock (_shutdownLock)
501503
{
502-
// TODO: Exception is always allocated. Consider only allocating if receive hasn't completed.
503-
_shutdownReason = shutdownReason ?? new ConnectionAbortedException("The QUIC transport's send loop completed gracefully.");
504+
_shutdownReason = shutdownReason ?? SendGracefullyCompletedException;
504505
QuicLog.StreamShutdownWrite(_log, this, _shutdownReason.Message);
505506

506507
_stream.Shutdown();

0 commit comments

Comments
 (0)