Skip to content

Commit e3df408

Browse files
author
Kai Ruhnau
committed
Dispose the socket when the client closes the connection
aspnet#62
1 parent a0c2ef0 commit e3df408

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ private void OnRead(int status, Exception error)
9292
SocketInput.RemoteIntakeFin = true;
9393
_read.Dispose();
9494
_read = null;
95+
_listener.RemoveConnection(this);
96+
_socket.Dispose();
9597

9698
if (errorDone && error != null)
9799
{
@@ -136,6 +138,9 @@ void IConnectionControl.End(ProduceEndType endType)
136138
KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0);
137139
Thread.Post(() =>
138140
{
141+
if (_read == null)
142+
return;
143+
139144
KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1);
140145
new UvShutdownReq(
141146
Thread.Loop,
@@ -158,7 +163,10 @@ void IConnectionControl.End(ProduceEndType endType)
158163
Thread.Post(() =>
159164
{
160165
_listener.RemoveConnection(this);
161-
_read?.Dispose(); // Remove the ? once connections closed by the client work
166+
if (_read == null)
167+
return;
168+
169+
_read.Dispose();
162170
_socket.Dispose();
163171
KestrelTrace.Log.ConnectionStop(_connectionId);
164172
});

0 commit comments

Comments
 (0)