[rabbitmq-discuss] .Net RabbitMQ.Client Issue: Deadlock on ConnectionShutdown

Derek Greer dbgreer at gmail.com
Tue Aug 21 15:10:43 BST 2012

My apologizes, I should have included the version number.  I see this
behavior using version 2.8.4 from NuGet.  Perhaps you're testing with a
different version?  The issue appears to be related to the use of the
BlockingCell class used as part of the ShutdownContinuation.

Concerning the example, you're correct that this example poses a race
condition and should be using a try/catch rather than checking for
IsOpen().  That aside, there should never be a case when a client of the
.Net rabbitmq client should be able to call .Close() and cause the API to
block indefinitely.

I appreciate your pointing me to the use of the IModel.ModelShutdown.  I
would have thought that event would be raised any time the model was closed
rather than being raised exclusively due to a connection shutdown.  I'll
use that if I have to, but wouldn't you agree that clients of the API
should be able to subscribe to the IConnection.ConnectionShutdown event to
be alerted to connection shutdowns?

On Tue, Aug 21, 2012 at 5:49 AM, Emile Joubert <emile at rabbitmq.com> wrote:

> Hi Derek,
> On 20/08/12 19:29, Derek Greer wrote:
> > There appears to be a deadlock if you attempt to dispose, close, or
> > abort a channel within the context of an IConnection.ConnectionShutdown
> > event.
> Instead of deadlock I get an IO exception. An attempt to close the
> channel requires network access, but it is no longer possible for the
> channel to communicate over the network.
> System.IO.IOException:
>  Unable to write data to the transport connection:
>  An existing connection was forcibly closed by the remote host.
> System.Net.Sockets.SocketException:
>  An existing connection was forcibly closed by the remote host
> > if (channel != null && channel.IsOpen)
> > {
> > Console.WriteLine("Closing channel ...");
> > channel.Close(); // <- Never returns
> > Console.WriteLine("Channel closed.");
> > }
> This code is flawed, because the state of the channel could change
> between the query and the action. There is no need to explicitly shut
> down the channel when the connection shuts down as this will be done by
> the library. Parties can register their interest in channel shutdown
> using IModel.ModelShutdown.
> -Emile

Derek Greer
dbgreer at gmail.com     | @derekgreer <http://twitter.com/derekgreer>
lostechies.com <http://derekgreer.lostechies.com/> |
 | aspiringcraftsman.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120821/8e679c41/attachment.htm>

More information about the rabbitmq-discuss mailing list