<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Ok, last one today, I promise.<br>
<br>
I solved this problem my adding some explicit locks in Subscription and
SimpleRpcServer. I tried to checkout the latest source (on linux,
cygwin, and tortoiseHG) but kept getting a zlib error, so this patch is
against the source in rabbitmq-dotnet-client-1.5.3.zip downloaded from
<a class="moz-txt-link-freetext" href="http://www.rabbitmq.com/dotnet.html">http://www.rabbitmq.com/dotnet.html</a>.<br>
<br>
This patch makes SimpleRpcServer.Close threadsafe by adding:<br>
<ol>
<li>locking SimpleRpcServer.m_subscription around the body of
SimpleRpcServer.MainLoop's foreach (so we can't close while processing)</li>
<li>checking for a null Subscription.Consumer before processing a
message in SimpleRpcServer.MainLoop, but after we've locked
m_subscription (to ensure we don't process after we've closed)<br>
</li>
<li>locking this around the body of Subscription.Close (to ensure we
don't close that same subscription at the same time)<br>
</li>
</ol>
I *think* that solves the potential race conditions. It certainly
makes my tests work, and running "nant unit" on the 1.5.3 source gives
2 failures in TestSharedQueue.cs that look timing-related.<br>
<br>
Thanks,<br>
<pre class="moz-signature" cols="72">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</pre>
<br>
<br>
Ryan Davis wrote:
<blockquote cite="mid:4A2EB25D.10907@acceleration.net" type="cite">
<pre wrap="">Ryan Davis wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I'm going to add a flag and test out calling Close() from various points
in HandleCall/HandleCast/ProcessRequest.
</pre>
</blockquote>
<pre wrap=""><!---->Wow, I really didn't think that one through.
HandleCall/HandleCast/ProcessRequest are only called when there is a
message to process. If there is no message to process, the
SimpleRpcServer is blocked on Subscription.Next(), and will never
exit. My current test case starts a SimpleRpcServer, then tries to
stop it, without sending any messages.
I changed my code so if the SimpleRpcServer sees a certain byte[]
message (stored as ShutdownKey), it will close itself:
public override void HandleCast(bool isRedelivered, IBasicProperties
requestProperties, byte[] body)
{
for (var i = 0; i < body.Length; i++) {
if (body[i] != ShutdownKey[i]) return;
}
Close(); //we must have matched, shut down.
}
As I expected, this throws a different exception:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at RabbitMQ.Client.MessagePatterns.Subscription.Next() in d:\Projects\rabbitmq-dotnet-client-1.5.3\src\client\messagepatterns\Subscription.cs:line 323
at RabbitMQ.Client.MessagePatterns.Subscription.System.Collections.IEnumerator.MoveNext() in d:\Projects\rabbitmq-dotnet-client-1.5.3\src\client\messagepatterns\Subscription.cs:line 437
at RabbitMQ.Client.MessagePatterns.SimpleRpcServer.MainLoop() in d:\Projects\rabbitmq-dotnet-client-1.5.3\src\client\messagepatterns\SimpleRpcServer.cs:line 206
I'm going to start mucking about in SimpleRpcServer.cs/Subscription.cs
to see what's the smalled change I can make to fix it.
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
_______________________________________________
rabbitmq-discuss mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a>
<a class="moz-txt-link-freetext" href="http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss">http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a>
</pre>
</blockquote>
</body>
</html>