File tree Expand file tree Collapse file tree 4 files changed +35
-7
lines changed Expand file tree Collapse file tree 4 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 3535 "src\\Servers\\Kestrel\\test\\Sockets.BindTests\\Sockets.BindTests.csproj",
3636 "src\\Servers\\Kestrel\\test\\Sockets.FunctionalTests\\Sockets.FunctionalTests.csproj",
3737 "src\\Servers\\Kestrel\\tools\\CodeGenerator\\CodeGenerator.csproj",
38- "src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj"
38+ "src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj",
39+ "src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj"
3940 ]
4041 }
4142}
Original file line number Diff line number Diff line change @@ -69,20 +69,25 @@ private void SetBufferList(in ReadOnlySequence<byte> buffer)
6969 Debug . Assert ( ! buffer . IsEmpty ) ;
7070 Debug . Assert ( ! buffer . IsSingleSegment ) ;
7171
72- if ( BufferList == null )
72+ var buffers = BufferList ;
73+
74+ if ( buffers == null )
7375 {
74- BufferList = new List < ArraySegment < byte > > ( ) ;
76+ buffers = new List < ArraySegment < byte > > ( ) ;
7577 }
7678 else
7779 {
7880 // Buffers are pooled, so it's OK to root them until the next multi-buffer write.
79- BufferList . Clear ( ) ;
81+ buffers . Clear ( ) ;
8082 }
8183
8284 foreach ( var b in buffer )
8385 {
84- BufferList . Add ( b . GetArray ( ) ) ;
86+ buffers . Add ( b . GetArray ( ) ) ;
8587 }
88+
89+ // The act of setting this list, sets the buffers in the internal buffer list
90+ BufferList = buffers ;
8691 }
8792 }
8893}
Original file line number Diff line number Diff line change 1+ using System ;
12using System . Collections . Concurrent ;
23using System . IO . Pipelines ;
34
45namespace Microsoft . AspNetCore . Server . Kestrel . Transport . Sockets . Internal
56{
6- internal class SocketSenderPool
7+ internal class SocketSenderPool : IDisposable
78 {
89 private const int MaxQueueSize = 1024 ; // REVIEW: Is this good enough?
910
1011 private readonly ConcurrentQueue < SocketSender > _queue = new ( ) ;
1112 private readonly PipeScheduler _scheduler ;
13+ private bool _disposed ;
1214
1315 public SocketSenderPool ( PipeScheduler scheduler )
1416 {
@@ -26,7 +28,7 @@ public SocketSender Rent()
2628
2729 public void Return ( SocketSender sender )
2830 {
29- if ( _queue . Count > MaxQueueSize )
31+ if ( _disposed || _queue . Count > MaxQueueSize )
3032 {
3133 sender . Dispose ( ) ;
3234 return ;
@@ -36,5 +38,18 @@ public void Return(SocketSender sender)
3638
3739 _queue . Enqueue ( sender ) ;
3840 }
41+
42+ public void Dispose ( )
43+ {
44+ if ( ! _disposed )
45+ {
46+ _disposed = true ;
47+ while ( _queue . TryDequeue ( out var sender ) )
48+ {
49+ sender . Dispose ( ) ;
50+ }
51+ }
52+ }
53+
3954 }
4055}
Original file line number Diff line number Diff line change @@ -204,6 +204,13 @@ public ValueTask DisposeAsync()
204204
205205 // Dispose the memory pool
206206 _memoryPool . Dispose ( ) ;
207+
208+ // Dispose any pooled senders
209+ foreach ( var setting in _settings )
210+ {
211+ setting . SocketSenderPool . Dispose ( ) ;
212+ }
213+
207214 return default ;
208215 }
209216
You can’t perform that action at this time.
0 commit comments