Welcome to MSDN Blogs Sign in | Join | Help

Avoiding OneWay Deadlocks

I have two web services and I'm seeing a deadlock when making calls between them. The operation calls are marked as OneWay. How do I fix this? And, how is it even possible for one-way calls to block?

Marking an operation with the OneWay attribute doesn't offer any magical protection against deadlocks. The OneWay attribute means that in messaging terms, there is no application data that the service is expected to return as a result of the call. However, one-way calls still need to wait for the service to accept transmission of the message. A one-way call is complete when the service acknowledges that the message has successfully arrived (although the definition of successful can vary a bit). We've seen this before in HTTP, where successful acknowledgement takes the form of a 202 Accepted response.

There's a number of reasons then why a service might appear to have deadlocked. The service could simply be really slow and has either not accepted the connection or not finished processing to the point where it can send the acknowledgement. Now that you know that the one-way call can block, it takes more sleuthing before you can declare that a deadlock is taking place. The operation call could be held in limbo for a while because of the ConcurrencyMode setting. Setting ConcurrencyMode to Single prevents the service from taking a second call in while an existing call is underway. The operation call could also be waiting for the SynchronizationContext to become free. Basically, the problem with the one-way call could be almost any of the problems that you'd associate with a standard bidirectional call. Applying OneWay attributes to your calls does not get you out of having to debug your service deadlocks.

Next time: How HostNameComparisonMode Works

Published Wednesday, October 18, 2006 5:00 AM by Nicholas Allen

Comments

Wednesday, October 18, 2006 9:59 AM by Mike Bosch

# re: Avoiding OneWay Deadlocks

So what is the proper way to make the calls "true" fire and forget?  It seems this is more of a fire, wait to see if you hit your target, then forget.  

Wednesday, October 18, 2006 12:08 PM by Nicholas Allen's Indigo Blog

# TransportWithMessageCredential Over TCP

After switching from message security to transport security, I'm seeing a bunch of weird protocols being

Wednesday, October 18, 2006 2:23 PM by Nicholas Allen

# re: Avoiding OneWay Deadlocks

Mike, that's exactly the right way to think about OneWay tagged operation calls.

Having true fire-and-forget means that your channels must be able to return immediately after sending a message.  Typically this requires you to have no delivery guarantees (messages may be lost, duplicated, misordered, whatever along the way).  Datagram transports, such as UDP, are an example of channels that can do this.  Asynchronous transports, such as mail or queues, can be pretty close to fire-and-forget.  They still have to wait for the store to accept the message but they don't have to wait for delivery or processing.

Thursday, October 19, 2006 9:07 AM by Sam Gentile

# New and Notable 116

Now that I got my Feed Demon back, I actually have some stuff in the queue that is not so "new" but perhaps

Monday, October 23, 2006 8:56 PM by Brian Mowbray

# re: Avoiding OneWay Deadlocks

We used the timeout setting to help mitigate a lock or does this only apply to the soapclient call? The default setting is 2 minutes.

Tuesday, October 24, 2006 3:45 AM by Nicholas Allen

# re: Avoiding OneWay Deadlocks

Timeouts are an expensive runtime mitigation that could used for some types of cross-service deadlocks.  I would not recommend that as a first line approach if you have any other practical alternatives.  You're going to tie up resources on both the client and server waiting for the call to complete.  After failing, you're going to have to try again, hoping that this time the call goes through.  You're also going to get a whole lot of junk in your logs because of the failures and aborts.  

Tuesday, September 25, 2007 3:05 AM by Sam Gentile

# New and Notable 116

Now that I got my Feed Demon back, I actually have some stuff in the queue that is not so "new"

Wednesday, December 03, 2008 6:20 PM by Sam Gentile's Blog

# New and Notable 116

Now that I got my Feed Demon back, I actually have some stuff in the queue that is not so "new" but perhaps still "notable." Architecture/CAB/Smart Client Oldie but goodie: Eugenio has compiled a list of CAB and Smart Client Software

New Comments to this post are disabled
 
Page view tracker