dotnet / dotnet/wcf

Synchron calls after Asynchron calls with no result blocks forever

Open
#5,626 4 comments 0 reactions 2 assignees Claimed by @imcarolwang View on GitHub
triaged
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

**Describe the bug**
When I call a sync WCF OperatinContract after an async OperationContract call with no result the synchron call is never resolved. If the perverious async call has a result this problem does not happen.

**To Reproduce**
Create a WCF Service with Async Methods that returns somsthing (Test1Async) and one that returns nothing (Test2Async) and add a sync Method (Test3)
```cs
[ServiceContract]
public interface ITestService
{
[OperationContract]
Task Test1Async(string text);

[OperationContract]
Task Test2Async(string text);

[OperationContract]
string Test3(string text);
}
```

Call the WCF Interface (see code below with comments)

```cs
private static async Task CallNetPipeBinding(string hostAddr)
{
IClientChannel channel = null;

var binding = new NetNamedPipeBinding();

var factory = new ChannelFactory(binding, new EndpointAddress($"{hostAddr}/netPipe"));
await Task.Factory.FromAsync(factory.BeginOpen, factory.EndOpen, TaskCreationOptions.None);
try
{
ITestService client = factory.CreateChannel();
channel = client as IClientChannel;
await Task.Factory.FromAsync(channel.BeginOpen, channel.EndOpen, TaskCreationOptions.None);

await client.Test1Async("Test");
client.Test3("Test");// This call works because the perverious call returns something
await client.Test2Async("Test");
client.Test3("Test");// This call does not work becausee the pereverious call returns nothing
}
finally
{
factory.Close();
}
}
```

**Expected behavior**
Synchron calls after async call with no result don't block forever.

**Additional context**
I think the problem is that the TaskCompletionSource withtout result is not created with `TaskCreationOptions.RunContinuationsAsynchronously`

TaskCompletionSource Creation with return Type:
https://github.com/dotnet/wcf/blob/c7b4036b7f103d60df2b3fad4d5f8a74f2adfad4/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/ServiceChannelProxy.cs#L318

https://github.com/dotnet/wcf/blob/c7b4036b7f103d60df2b3fad4d5f8a74f2adfad4/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/ServiceChannelProxy.cs#L174

TaskCompletionSource Creation without return Type:
https://github.com/dotnet/wcf/blob/c7b4036b7f103d60df2b3fad4d5f8a74f2adfad4/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/ServiceChannelProxy.cs#L213

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.