Don't invoke continuations inline in OnCompleted (#12261)
This commit is contained in:
parent
4ba66f05bf
commit
fb12909417
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl
|
||||
{
|
||||
|
|
@ -29,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl
|
|||
if (ReferenceEquals(_callback, _callbackCompleted) ||
|
||||
ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted))
|
||||
{
|
||||
continuation();
|
||||
Task.Run(continuation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,15 +53,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
{
|
||||
// There should never be a race between IsCompleted and OnCompleted since both operations
|
||||
// should always be on the libuv thread
|
||||
|
||||
if (ReferenceEquals(_callback, _callbackCompleted) ||
|
||||
ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted))
|
||||
if (ReferenceEquals(_callback, _callbackCompleted))
|
||||
{
|
||||
Debug.Fail($"{typeof(LibuvAwaitable<TRequest>)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, running callback inline.");
|
||||
|
||||
// Just run it inline
|
||||
continuation();
|
||||
Debug.Fail($"{typeof(LibuvAwaitable<TRequest>)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, scheduling callback.");
|
||||
}
|
||||
|
||||
_callback = continuation;
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
|
|
|
|||
Loading…
Reference in New Issue