diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 726d0372ca..59e5ff2e22 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -86,6 +86,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal // Dispose the socket(should noop if already called) _socket.Dispose(); + _receiver.Dispose(); + _sender.Dispose(); } catch (Exception ex) { diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs index 150978e473..2116c03cd5 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -7,7 +7,7 @@ using System.Net.Sockets; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { - public class SocketReceiver + public class SocketReceiver : IDisposable { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); @@ -37,5 +37,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } + + public void Dispose() + { + _eventArgs.Dispose(); + } } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index a8b0727c0a..26e22b664d 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -11,7 +11,7 @@ using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { - public class SocketSender + public class SocketSender : IDisposable { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); @@ -98,5 +98,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _bufferList; } + + public void Dispose() + { + _eventArgs.Dispose(); + } } }