Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Newton-King <james@newtonking.com>2022-07-31 13:24:26 +0300
committerJames Newton-King <james@newtonking.com>2022-07-31 13:24:26 +0300
commitc298fb3aad1eefbf00fd59455d62e6247ccc4bd4 (patch)
treebaea3ff7254295deb4f8d2b2ad0f2a0bee258b13
parenta85675d5da8e42909f0ece7e70df9af35615707d (diff)
HTTP/3: Fix allocating context every request, use QuicStream.DisposeAsyncjamesnk/http3-streamcontext
-rw-r--r--src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs17
-rw-r--r--src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs16
2 files changed, 18 insertions, 15 deletions
diff --git a/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs b/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs
index b1ecf4dac3..4993ea7f12 100644
--- a/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs
+++ b/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs
@@ -332,12 +332,12 @@ internal sealed class Http3Connection : IHttp3StreamLifetimeHandler, IRequestPro
Debug.Assert(streamDirectionFeature != null);
Debug.Assert(streamIdFeature != null);
- var context = CreateHttpStreamContext(streamContext);
-
// unidirectional stream
if (!streamDirectionFeature.CanWrite)
{
- if (context.ServiceContext.ServerOptions.EnableWebTransportAndH3Datagrams)
+ var context = CreateHttpStreamContext(streamContext);
+
+ if (_context.ServiceContext.ServerOptions.EnableWebTransportAndH3Datagrams)
{
var pendingStream = new Http3PendingStream(context, streamIdFeature.StreamId);
@@ -369,8 +369,9 @@ internal sealed class Http3Connection : IHttp3StreamLifetimeHandler, IRequestPro
// bidirectional stream
else
{
- if (context.ServiceContext.ServerOptions.EnableWebTransportAndH3Datagrams)
+ if (_context.ServiceContext.ServerOptions.EnableWebTransportAndH3Datagrams)
{
+ var context = CreateHttpStreamContext(streamContext);
var pendingStream = new Http3PendingStream(context, streamIdFeature.StreamId);
_streamLifetimeHandler.OnUnidentifiedStreamReceived(pendingStream);
@@ -386,12 +387,12 @@ internal sealed class Http3Connection : IHttp3StreamLifetimeHandler, IRequestPro
}
else
{
- await CreateHttp3Stream(streamContext, context, application, streamIdFeature.StreamId);
+ await CreateHttp3Stream(streamContext, application, streamIdFeature.StreamId);
}
}
else
{
- await CreateHttp3Stream(streamContext, context, application, streamIdFeature.StreamId);
+ await CreateHttp3Stream(streamContext, application, streamIdFeature.StreamId);
}
}
}
@@ -512,7 +513,7 @@ internal sealed class Http3Connection : IHttp3StreamLifetimeHandler, IRequestPro
}
}
- private async Task CreateHttp3Stream<TContext>(ConnectionContext streamContext, Http3StreamContext context, IHttpApplication<TContext> application, long streamId) where TContext : notnull
+ private async Task CreateHttp3Stream<TContext>(ConnectionContext streamContext, IHttpApplication<TContext> application, long streamId) where TContext : notnull
{
// http request stream
// https://quicwg.org/base-drafts/draft-ietf-quic-http.html#section-5.2-2
@@ -538,7 +539,7 @@ internal sealed class Http3Connection : IHttp3StreamLifetimeHandler, IRequestPro
// A stream will only be cached if the transport stream itself is reused.
if (!persistentStateFeature.State.TryGetValue(StreamPersistentStateKey, out var s))
{
- stream = new Http3Stream<TContext>(application, context);
+ stream = new Http3Stream<TContext>(application, CreateHttpStreamContext(streamContext));
persistentStateFeature.State.Add(StreamPersistentStateKey, stream);
}
else
diff --git a/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs b/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs
index 65786a7cac..d1598825cb 100644
--- a/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs
+++ b/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs
@@ -559,15 +559,17 @@ internal partial class QuicStreamContext : TransportConnection, IPooledStream, I
&& !_serverAborted
&& _shutdownReadReason == null
&& _shutdownWriteReason == null;
+ }
- if (!CanReuse)
- {
- DisposeCore();
- }
-
- _stream.Dispose();
- _stream = null!;
+ if (!CanReuse)
+ {
+ DisposeCore();
}
+
+ await _stream.DisposeAsync();
+
+ // QuicStream can't be reused. Don't hang onto it when QuicStreamContext it potentially cached.
+ _stream = null!;
}
public void Dispose()