Просмотр исходного кода

Dispose streams that don't fit in pool (#30995)

* Dispose streams that don't fit in pool

* PR feedback
James Newton-King 5 лет назад
Родитель
Сommit
6adb596f8d
1 измененных файлов с 9 добавлено и 17 удалено
  1. 9 17
      src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

+ 9 - 17
src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

@@ -668,21 +668,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
             return streamContext;
             return streamContext;
         }
         }
 
 
-        private void ReturnStream(Http2Stream stream)
-        {
-            // We're conservative about what streams we can reuse.
-            // If there is a chance the stream is still in use then don't attempt to reuse it.
-            Debug.Assert(stream.CanReuse);
-
-            if (StreamPool.Count < MaxStreamPoolSize)
-            {
-                // This property is used to remove unused streams from the pool
-                stream.DrainExpirationTicks = SystemClock.UtcNowTicks + StreamPoolExpiryTicks;
-
-                StreamPool.Push(stream);
-            }
-        }
-
         private Task ProcessPriorityFrameAsync()
         private Task ProcessPriorityFrameAsync()
         {
         {
             if (_currentHeadersStream != null)
             if (_currentHeadersStream != null)
@@ -1181,12 +1166,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
         private void RemoveStream(Http2Stream stream)
         private void RemoveStream(Http2Stream stream)
         {
         {
             _streams.Remove(stream.StreamId);
             _streams.Remove(stream.StreamId);
-            if (stream.CanReuse)
+
+            if (stream.CanReuse && StreamPool.Count < MaxStreamPoolSize)
             {
             {
-                ReturnStream(stream);
+                // Pool and reuse the stream if it finished in a graceful state and there is space in the pool.
+
+                // This property is used to remove unused streams from the pool
+                stream.DrainExpirationTicks = SystemClock.UtcNowTicks + StreamPoolExpiryTicks;
+
+                StreamPool.Push(stream);
             }
             }
             else
             else
             {
             {
+                // Stream didn't complete gracefully or pool is full.
                 stream.Dispose();
                 stream.Dispose();
             }
             }
         }
         }