Skip to content

HTTP/3: Avoid ConnectionAbortedException allocations #42708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,6 @@ public async Task ProcessRequestAsync<TContext>(IHttpApplication<TContext> appli
}
finally
{
var streamError = error as ConnectionAbortedException
?? new ConnectionAbortedException("The stream has completed.", error!);

await Input.CompleteAsync();

// Once the header is finished being received then the app has started.
Expand Down Expand Up @@ -692,6 +689,9 @@ public async Task ProcessRequestAsync<TContext>(IHttpApplication<TContext> appli
}
catch
{
var streamError = error as ConnectionAbortedException
?? new ConnectionAbortedException("The stream has completed.", error!);

Abort(streamError, Http3ErrorCode.ProtocolError);
throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal;

internal partial class QuicStreamContext : TransportConnection, IPooledStream, IDisposable
{
private static readonly ConnectionAbortedException SendGracefullyCompletedException = new ConnectionAbortedException("The QUIC transport's send loop completed gracefully.");

// Internal for testing.
internal Task _processingTask = Task.CompletedTask;

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

_stream.Shutdown();
Expand Down