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

Commit 24d742a

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/no-threadpool-oncompleted' into socket-memorypool2
2 parents 5c64979 + 58d2e63 commit 24d742a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO;
66
using System.Runtime.CompilerServices;
77
using System.Threading;
8-
using System.Threading.Tasks;
98
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
109

1110
namespace Microsoft.AspNet.Server.Kestrel.Http
@@ -40,7 +39,7 @@ public bool IsCompleted
4039
{
4140
get
4241
{
43-
return Equals(_awaitableState, _awaitableIsCompleted);
42+
return _awaitableState == _awaitableIsCompleted;
4443
}
4544
}
4645

@@ -128,6 +127,7 @@ public void IncomingComplete(int count, Exception error)
128127
if (awaitableState != _awaitableIsCompleted &&
129128
awaitableState != _awaitableIsNotCompleted)
130129
{
130+
// Waiting read, run it on thread pool rather than IO thread
131131
ThreadPool.QueueUserWorkItem((o) => ((Action)o)(), awaitableState);
132132
}
133133
}
@@ -194,11 +194,13 @@ public void OnCompleted(Action continuation)
194194
}
195195
else if (awaitableState == _awaitableIsCompleted)
196196
{
197-
ThreadPool.QueueUserWorkItem((o) => ((Action)o)(), continuation);
197+
// Read already completed, continue on calling thread
198+
continuation();
198199
}
199200
else
200201
{
201202
// THIS IS AN ERROR STATE - ONLY ONE WAITER CAN WAIT
203+
throw new InvalidOperationException("Already an awaited read");
202204
}
203205
}
204206

0 commit comments

Comments
 (0)