[rabbitmq-discuss] .NET client SimpleRpcServer question
Ryan Davis
ryan at acceleration.net
Tue Jun 9 19:21:15 BST 2009
Ryan Davis wrote:
> I don't follow how the foreach in MainLoop would
> terminate and start Disposing of things before the controller thread had
> gotten through subscription.Close() to set m_consumer to null.
>
> I've got a unit test that reproduces this behavior, so I'll be playing
> with this today, stepping through to better understand what is happening.
>
I think I figured it out. The C# "foreach" loop also acts like a
"using" statement, and will call Dispose() on my subscription when it
finishes, which I didn't realize
(http://mark.michaelis.net/Blog/CForeachWithArrays.aspx). This means
I'm actually calling Subscription.Close() a total of 4 times.
Here's the chronology
# controller thread: calls RpcServer.Close() -> Subscription.Close() ->
Model.BasicCancel()
# worker thread: throws and catches exceptions in Subscription.Next(),
terminating MainLoop's foreach
# worker thread: calls Subscription.Dispose() -> Subscription.Close() ->
Model.BasicCancel()
# controller thread: completes Model.BasicCancel(), sets some variables
to null
# worker thread: nullref trying to use those variables
I added some Console.WriteLine statements to the Close/Dispose methods,
and that solved the problem, so it's definitely a race condition when
calling Close() from another thread.
I'm going to add a flag and test out calling Close() from various points
in HandleCall/HandleCast/ProcessRequest.
Thanks,
Ryan Davis
Acceleration.net
Director of Programming Services
2831 NW 41st street, suite B
Gainesville, FL 32606
Office: 352-335-6500 x 124
Fax: 352-335-6506
More information about the rabbitmq-discuss
mailing list