mono / mono

Mono open source ECMA CLI, C# and .NET implementation.
https://www.mono-project.com
Other
11.13k stars 3.82k forks source link

Calling Close() on WCF client channel times out on Mono Mac but works on Windows #21163

Open DareDevilDenis opened 3 years ago

DareDevilDenis commented 3 years ago

I have a WCF server running on Windows (.Net framework 4.8) using a NetTCP binding. I have both Windows and Mac clients. The same binaries are used on both the Windows and Mac clients. The Windows client is running on .Net framework 4.8, the Mac client is running on Mono 6.12.0.122.

The client is very simple:

It works fine running the client on Windows however when running the client on Mac the call to Close() on the channel always hangs and times out after 1 minute. Note: In both cases the server sees the disconnection immediately after it is sent from the client.

Steps to Reproduce

Using the attached solution: WCFTest.zip

  1. Run the server on Windows with your chosen port:
WCFTestServer.exe 50999
  1. Run the client on Windows with passing the IP address and port of the server:

    WCFTestClient.exe 192.168.10.2 50999
  2. Run the same client on MacOS:

    mono WCFTestClient.exe 192.168.10.2 50999

Output on Windows client:

The channel is closed immediately as expected:

01:54:45.030 WCFTestClient. Syntax: WCFTestClient.exe [serverIP] [serverPort]
01:54:45.030 Connecting to server IP address:192.168.10.2 Port=50999...
01:54:45.261 Calling Handshake
01:54:45.416 Handshake returned True
01:54:45.416 CloseChannel: Calling Close() on channel
01:54:45.416 CloseChannel finished

Output on MacOS client:

The call to Close() on channel hangs and then times out after 1 minute:

01:49:27.768 WCFTestClient. Syntax: WCFTestClient.exe [serverIP] [serverPort]
01:49:27.999 Connecting to server IP address:192.168.10.2 Port=50999...
01:49:28.590 Calling Handshake
01:49:29.091 Handshake returned True
01:49:29.091 CloseChannel: Calling Close() on channel
01:50:29.106 CloseChannel exception: System.TimeoutException: The operation has timed out.
  at System.ServiceModel.ClientRealProxy.Invoke (System.Runtime.Remoting.Messaging.IMessage inputMessage) [0x00019] in <98645fec45894118b9ff6a6cd5761ead>:0 
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (System.Runtime.Remoting.Proxies.RealProxy rp, System.Runtime.Remoting.Messaging.IMessage msg, System.Exception& exc, System.Object[]& out_args) [0x000d6] in <36514b14425c4337b446653c547aa9c3>:0 
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_remoting_wrapper(intptr,intptr)
  at (wrapper remoting-invoke) System.ServiceModel.ICommunicationObject.Close()
  at WCFTestClient.Program.CloseChannel () [0x0000d] in <a1109b1888c6463d93105aac786e656a>:0 
01:50:29.106 CloseChannel: Calling Abort() on channel
01:50:29.107 CloseChannel finished
DareDevilDenis commented 3 years ago

By changing the channel factory from: channelFactory = new DuplexChannelFactory<IWCFTestInterface>(instanceContext, binding, endpointAddress);

To: channelFactory = new ChannelFactory<IWCFTestInterface>(binding, endpointAddress);

The Close() now works as expected on MacOS (i.e. it does not hang and timeout). However, this is not a workable solution because my project requires callbacks so I need a DuplexChannelFactory.