Skip to content

Commit fee23ca

Browse files
committed
Don't invoke continuations inline in OnCompleted
1 parent 892ea7e commit fee23ca

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/OutputFlowControlAwaitable.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.Runtime.CompilerServices;
77
using System.Threading;
8+
using System.Threading.Tasks;
89

910
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl
1011
{
@@ -29,7 +30,7 @@ public void OnCompleted(Action continuation)
2930
if (ReferenceEquals(_callback, _callbackCompleted) ||
3031
ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted))
3132
{
32-
continuation();
33+
Task.Run(continuation);
3334
}
3435
}
3536

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvAwaitable.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.Runtime.CompilerServices;
77
using System.Threading;
8+
using System.Threading.Tasks;
89
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking;
910

1011
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
@@ -57,10 +58,10 @@ public void OnCompleted(Action continuation)
5758
if (ReferenceEquals(_callback, _callbackCompleted) ||
5859
ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted))
5960
{
60-
Debug.Fail($"{typeof(LibuvAwaitable<TRequest>)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, running callback inline.");
61+
Debug.Fail($"{typeof(LibuvAwaitable<TRequest>)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, scheduling callback.");
6162

62-
// Just run it inline
63-
continuation();
63+
// Just schedule it
64+
Task.Run(continuation);
6465
}
6566
}
6667

0 commit comments

Comments
 (0)