Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit b449da0

Browse files
committed
Complete all outstanding callbacks on socket error
1 parent cad9980 commit b449da0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ private void ScheduleWrite()
140140
{
141141
_thread.Post(_this => _this.WriteAllPending(), this);
142142
}
143+
else
144+
{
145+
CompleteAllCallbacksWithError(_lastWriteError ?? new InvalidOperationException("Socket is closed"));
146+
}
143147
}
144148

145149
// This is called on the libuv event loop
@@ -177,6 +181,20 @@ private void WriteAllPending()
177181
throw;
178182
}
179183
}
184+
185+
private void CompleteAllCallbacksWithError(Exception error)
186+
{
187+
lock (_lockObj)
188+
{
189+
while (_callbacksPending.Count > 0)
190+
{
191+
var callbackContext = _callbacksPending.Dequeue();
192+
193+
// callback(error, state, calledInline)
194+
callbackContext.Callback(error, callbackContext.State, false);
195+
}
196+
}
197+
}
180198

181199
// This is called on the libuv event loop
182200
private void OnWriteCompleted(Queue<ArraySegment<byte>> writtenBuffers, int status, Exception error)

0 commit comments

Comments
 (0)