Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - WCF deadlock timeout on reentrant callback to Windows App

 
 
Old 03-01-2007   #1 (permalink)
Ryan S


 
 

WCF deadlock timeout on reentrant callback to Windows App

I have this setup:
- Using WCF with net-tcp binding.
- Have a singleton service (implements IService) that I want to be able to
publish "events" (currently the data published is just a String) to all
subscribers.
- An ISubscriber callback contract has: string GetName(void) and void
AddMessage(String msg).
- An IService contract that specifies its callback contract is ISubscriber.
- IService has void Subscribe(void) method.
- Service.Subscribe() uses
OperationContext.Current.GetCallbackChannel<ISubscriber>() to get the
"calling" ISubscriber.
- In Service.Subscribe(), the code gets the name of the calling ISubscriber
using ISubscriber.GetName(). This deadlocks in one case.
- The Service class and the Subscriber class are both marked
ConcurrencyMode.Multiple (Reentrant also deadlocks).

The Service.Subscribe() callback to ISubscriber.GetName() deadlocks if the
client is calling Subscribe() from the main Windows App thread (from a button
click). When the client uses a separate temporary thread to call Subscribe
it doesn't deadlock, also from a Console application it doesn’t deadlock. So
evidently the callback is deadlocking relative to the windows app main thread.

What does the WCF callback have to do with the windows app main thread?

Thanks,
Ryan


My System SpecsSystem Spec
Old 03-01-2007   #2 (permalink)
Joerg Jooss


 
 

Re: WCF deadlock timeout on reentrant callback to Windows App

Thus wrote Ryan,

> I have this setup:
> - Using WCF with net-tcp binding.
> - Have a singleton service (implements IService) that I want to be
> able to
> publish "events" (currently the data published is just a String) to
> all
> subscribers.
> - An ISubscriber callback contract has: string GetName(void) and void
> AddMessage(String msg).
> - An IService contract that specifies its callback contract is
> ISubscriber.
> - IService has void Subscribe(void) method.
> - Service.Subscribe() uses
> OperationContext.Current.GetCallbackChannel<ISubscriber>() to get the
> "calling" ISubscriber.
> - In Service.Subscribe(), the code gets the name of the calling
> ISubscriber
> using ISubscriber.GetName(). This deadlocks in one case.
> - The Service class and the Subscriber class are both marked
> ConcurrencyMode.Multiple (Reentrant also deadlocks).
> The Service.Subscribe() callback to ISubscriber.GetName() deadlocks if
> the client is calling Subscribe() from the main Windows App thread
> (from a button click). When the client uses a separate temporary
> thread to call Subscribe it doesn't deadlock, also from a Console
> application it doesn’t deadlock. So evidently the callback is
> deadlocking relative to the windows app main thread.
>
> What does the WCF callback have to do with the windows app main
> thread?


Since by default a WCF service uses [ServiceBehavior(UseSynchronizationContext
=true)], your callback gets marshalled back to the UI thread, becoming a
message dispatched to your Windows Form... and remains stuck there, because
your main UI thread is still busy waiting on Service.Subscribe() to complete.

Due to that marshalling behavior, the notion of your current ConcurrencyMode
can be highly misleading here. Actually, using anything else other than ConcurrencyMode.Single
can be rather dangerous in this particular scenario.

Cheers,
--
Joerg Jooss
news-reply@joergjooss.de


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Deadlock 2 shrinewars for vista help Gaming
Deadlock when logging to stdout and stderr PowerShell
Help! Reached a deadlock Vista security


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46