WCF Named Pipe synchronous calls deadlock for certain SynchronizationContexts #5080
Description
Describe the bug
WCF Named Pipe synchronous calls deadlock when called from a thread where the "current" SynchronizationContext is one which sends its work to the same thread (E.g. WindowsFormsSynchronizationContext).
To Reproduce
Steps to reproduce the behavior:
Attached is a sample that runs a WCF Named pipe service.
NetNamedPipeNet6.zip
There is a Console Application that connects to it and works correctly. There is a Winforms application that connects to it and exhibits the defect.
- Open the Solution WCFNetNamedPipe.sln
- Run the WCF_NewsService project.
- Run the WinFormsApp1 project.
- Press the button (this initiates a synchronous call to the service and displays a message box once the call returns).
Issue: this causes a deadlock.
Expected behavior
The expected behavior is that there is no deadlock.
The correct behavior can be observed by checking the "Workaround" checkbox in the WinFormsApp1. This temporarily removes the SynchronizationContext prior to calling the service.
The correct behavior can also be observed by running the ConsoleApp_Net6 project.
Additional context
It appears that the fix is likely to either be adding an await TaskHelpers.EnsureDefaultTaskScheduler();
somewhere in the flow.
It may be the case that this change addresses or has an affect on this issue:
#5044 for #4946
Is there a preview package with this change incorporated that can be tested?
Activity