Deadlock in my code possibly related to RX
-
Friday, January 13, 2012 9:47 AM
Hello everyone,
I'm encountering a deadlock situation in my code, where two synchronization blocks are involved. One of the blocks is managed in my code, another one - somewhere in RX (?). Could someone give me an idea where and when RX utilizes shared synchronization blocks that may be involved in more than one operation with observables?
Here is a stack trace of the thread when it deadlocked at the RX's (?) sync block. How could another thread acquire the same block, if it is internal to RX?
0595e76c 7c8285ec [GCFrame: 0595e76c]
0595e83c 7c8285ec [HelperMethodFrame_1OBJ: 0595e83c] System.Threading.Monitor.Enter(System.Object)
0595e894 0567f2ae System.Linq.Observable+<>c__DisplayClass2dd`1+<>c__DisplayClass2df+<>c__DisplayClass2e1[[System.__Canon, mscorlib]].<Merge>b__2d8(System.__Canon)
PARAMETERS:
this = 0x02263b74
x = 0x08e3b428
LOCALS:
0x0595e894 = 0x02263a3c [address of sync block from external code]
0595e8c4 043fcdf5 System.Collections.Generic.AnonymousObserver`1[[System.__Canon, mscorlib]].Next(System.__Canon)
PARAMETERS:
this = <no data>
value = <no data>
0595e8c8 043fc8ce System.Collections.Generic.AbstractObserver`1[[System.__Canon, mscorlib]].OnNext(System.__Canon)
PARAMETERS:
this = <no data>
value = <no data>
...0595e900 054b470e System.SynchronizedObserver`1[[System.__Canon, mscorlib]].Next(System.__Canon)
PARAMETERS:
this = 0x022f8860
value = <no data>
LOCALS:
0x0595e900 = 0x02261c04 [address of sync block from my code][related to call .Synchronize(0x02261c04)]...
Another thread:
07dae834 7c8285ec [HelperMethodFrame: 07dae834] System.Threading.Monitor.Enter(System.Object)
07dae888 075c8b2b XXX.XXX(XXX)
PARAMETERS:
this = 0x02261bec
fs = 0x08516318
LOCALS:
0x07dae8c4 = 0x00000000
0x07dae8c0 = 0x02261c04 [address of sync block from my code]
0x07dae8bc = 0x00000000
...<no signs in stack trace that lock at 0x02263a3c was acquired in user code>
...
Thanks in advance!
All Replies
-
Friday, January 13, 2012 10:38 AM
Hi,
It's hard to answer your question without some code that can repro the problem. If you can't repro in a short example, then could you at least post some code to indicate the kind of query that is deadlocking?
Also, why are you using the Synchronize operator? The Rx Design Guidelines (§5.8) recommends against using this operator except to fix sequences that aren't well-behaved in terms of the Rx grammar and serialization guarantees.
- Dave
http://davesexton.com/blog- Edited by Dave Sexton Friday, January 13, 2012 10:42 AM Spelling fix
- Marked As Answer by borovikpe Saturday, January 14, 2012 6:23 AM
-
Friday, January 13, 2012 10:41 AM
If you are looking for deadlocks in Rx, a good place to start is anywhere you "leave the monad" by calling First, Single, Last. These operators block and should be avoided if possible.
James Miles http://enumeratethis.com -
Saturday, January 14, 2012 6:31 AMThanks, it seems the cause is really in Synchronize usage. It was used to serialize RX marbles with some code block completion - seems to be invalid usage from my side.

