You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[RuntimeAsync] Awaiting a configured ValueTaskSource may end up running in a wrong context. #120709
ValueTaskSource can be configured to not run continuations in the current context (or scheduler).
That takes precedence over what awaiter wants.
For example an IO.Pipe can be configured to run callbacks/continuations in default/threadpool context. In such case immediate users of the IO.Pipe do not need to do ConfigureAwait(false).
Runtime async always considers what awaiter wants. In this case it results in testcase hangs infinitely.
[ConditionalFact(typeof(PlatformDetection),nameof(PlatformDetection.IsThreadingSupported))]publicasyncTaskUseSynchronizationContextFalseIgnoresSyncContextForReaderScheduler(){SynchronizationContextprevious=SynchronizationContext.Current;varsc=newCustomSynchronizationContext();try{SynchronizationContext.SetSynchronizationContext(sc);varpipe=newPipe(newPipeOptions(useSynchronizationContext:false));Func<Task>doRead=async()=>{ReadResultresult=awaitpipe.Reader.ReadAsync();pipe.Reader.AdvanceTo(result.Buffer.End,result.Buffer.End);pipe.Reader.Complete();};// This needs to run on the current SynchronizationContextTaskreading=doRead();PipeWriterbuffer=pipe.Writer;buffer.Write("Hello World"u8.ToArray());// Don't run code on our sync context (we just want to make sure the callbacks)// are scheduled on the sync contextawaitbuffer.FlushAsync().ConfigureAwait(false);// Nothing posted to the sync contextAssert.Equal(0,sc.Callbacks.Count);pipe.Writer.Complete();// Don't run code on our sync contextawaitreading.ConfigureAwait(false);}finally{SynchronizationContext.SetSynchronizationContext(previous);}}
Otherwise we end up posting the doRead continuation to the tracking CustomSynchronizationContext which only tracks Posts and does not run them, thus the test makes no progress.
Activity
dotnet-policy-service commentedon Oct 14, 2025
Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.
VSadov commentedon Oct 14, 2025
An example of affected testcase.
The part
should behave as
Otherwise we end up posting the
doReadcontinuation to the trackingCustomSynchronizationContextwhich only tracks Posts and does not run them, thus the test makes no progress.[RuntimeAsync] Fix for configured ValueTask sources (dotnet#120704)