[rabbitmq-discuss] Java client: channel shutdown notification while closing connection

Matthias Radestock matthias at rabbitmq.com
Fri Jan 21 20:02:24 GMT 2011


On 11/01/11 10:50, jiri at krutil.com wrote:
> I have a synchronized method registered as a shutdown listener on both
> the channel and the connection.
> One of our theads got stuck while trying to close the connection inside
> a method synchronized on the same lock as the shutdown listener.
> The thread was executing this code:
> private synchronized void closeConnection() throws IOException {
> connection.removeShutdownListener(this);
> if (connection.isOpen())
> connection.close();
> }
> [...]
> Apparently I am doing something wrong, but I'm not sure what is the
> correct way how to do these things.

The shutdown listeners get called in the main connection thread. That 
means they should not perform any possibly blocking AMQP operations. If 
they do then a deadlock can ensue.

> It seems Connection.close() is synchronous. Should I make my shutdown
> listener asynchronous? (not sure how I would do that)

Why are you calling connection.close() at all? The connection will 
already have been closed. After all, you are in the connection shutdown 
handler code.



More information about the rabbitmq-discuss mailing list