Skip to content

[RuntimeAsync] A few tests fail with runtime async due to unexpected use of sync context #119621

@VSadov

Description

@VSadov

Observed while enabling rt async in Libraires partition - #119432

Note: the issue may be not completely deterministic. I think I saw different number of failures in different runs. The runs had other changes, but none specifically for this failure, so it is possible that there is dependency on whether code suspends or takes fast path.

The failure looks like:

        Sync Ctx used:    at System.Environment.get_StackTrace() in E:\dotnet004\runtime\src\libraries\System.Private.CoreLib\src\System\Environment.cs:line 239
           at System.Threading.Tests.TrackingSynchronizationContext.Post(SendOrPostCallback d, Object state)
           at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask) in E:\dotnet004\runtime\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\TaskContinuation.cs:line 697
           at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in E:\dotnet004\runtime\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\Task.cs:line 3486
           at System.Threading.Tasks.Task`1.TrySetResult(TResult result) in E:\dotnet004\runtime\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\Future.cs:line 385
           at System.Threading.Tasks.TaskCompletionSource`1.TrySetResult(TResult result) in E:\dotnet004\runtime\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\TaskCompletionSource_T.cs:line 218

These are complicated scenarios involving HTTP server/client talking to each other asynchronously.
The tests deliberately set a synchronization context on the client's thread that tracks its use and subsequently fail if it ends up used.
Somehow we may end up using the context when runtime async is enabled.

An additional care may need to be taken to ensure that this is a real issue and not just artefact of particular way to test.
In a way it would still be an observable change and thus a compat concern.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions