Our Java client sometimes (randomly) can't publish a message:
AlreadyClosedException: clean connection shutdown; reason: Attempt to
use closed channel

The client uses a single connection and multiple channels across
multiple threads.

I'm seeing this error in a method, which creates a channel, publishes
a single message using basicPublish and closes the channel. It seems
that the problem occurs when the method is being invoked in a loop
from two threads at the same time. The channel is a local variable,
the connection is a member variable. The calls to
Connection.createChannel are not synchronized.

I have a shutdown listener registered on the connection, which did not
get called. The connection seems to be alive. Without restarting the
client or reconnecting, another attempt to publish succeeds.

We are using broker and client version 2.1.0.
Below is broker status after such an error while the client is still up.

Any ideas?

Cheers
Jiri



rabbitmqctl list_channels
Listing channels ...
<rabbit at titan.11596.0> capacity false 1 0
<rabbit at titan.11600.0> capacity false 0 0
...done.

rabbitmqctl list_connections
Listing connections ...
capacity 172.20.12.132 1187 running
...done.

rabbitmqctl status
Status of node rabbit at titan ...
[{running_applications,[{rabbit,"RabbitMQ","2.1.0"},
{ssl,"Erlang/OTP SSL application","4.0.1"},
{public_key,"Public key infrastructure","0.8"},
{crypto,"CRYPTO version 2","2.0.1"},
{os_mon,"CPO CXC 138 46","2.2.5"},
{sasl,"SASL CXC 138 11","2.1.9.2"},
{mnesia,"MNESIA CXC 138 12","4.4.15"},
{stdlib,"ERTS CXC 138 10","1.17.1"},
{kernel,"ERTS CXC 138 10","2.14.1"}]},
{nodes,[{disc,[rabbit at titan]}]},
{running_nodes,[rabbit at titan]}]
...done.

Search Discussions

  • Matthias Radestock at Nov 3, 2010 at 10:12 am
    Jiri,
    On 03/11/10 10:08, jiri at krutil.com wrote:
    Our Java client sometimes (randomly) can't publish a message:
    AlreadyClosedException: clean connection shutdown; reason: Attempt to
    use closed channel
    Is there any error message in the server log?

    Regards,

    Matthias.
  • Jiri at Nov 3, 2010 at 11:27 am
    Matthias,
    Our Java client sometimes (randomly) can't publish a message:
    AlreadyClosedException: clean connection shutdown; reason: Attempt to
    use closed channel
    Is there any error message in the server log?
    There are errors like this on the server, which might very well be related:

    =ERROR REPORT==== 3-Nov-2010::11:04:24 ===
    connection <0.17229.0> (running), channel 4 - error:
    {amqp_error,not_found,
    "no exchange 'foo' in vhost '/capacity/development'",
    'basic.publish'}

    Is it possible that this is the actual problem and the Java client is
    only reporting misleading error messages?

    Cheers
    Jiri
  • Matthias Radestock at Nov 3, 2010 at 11:40 am
    Jiri,
    On 03/11/10 11:27, jiri at krutil.com wrote:
    There are errors like this on the server, which might very well be related:

    =ERROR REPORT==== 3-Nov-2010::11:04:24 ===
    connection <0.17229.0> (running), channel 4 - error:
    {amqp_error,not_found,
    "no exchange 'foo' in vhost '/capacity/development'",
    'basic.publish'}

    Is it possible that this is the actual problem Yes.
    and the Java client is only reporting misleading error messages?
    Publishing is asynchronous, which means basic.publish itself will never
    "return" any error that it may have triggered. Instead the error is
    handled asynchronously by the client library code. The
    AlreadyClosedException you are seeing is due to library having received
    and processed the server-initiated channel.close already by the time the
    application tries to close the channel.

    Regards,

    Matthias.
  • Jiri at Nov 3, 2010 at 11:48 am
    Matthias,
    Is it possible that this is the actual problem
    and the Java client is only reporting misleading error messages?
    Publishing is asynchronous, which means basic.publish itself will
    never "return" any error that it may have triggered. Instead the
    error is handled asynchronously by the client library code. The
    AlreadyClosedException you are seeing is due to library having
    received and processed the server-initiated channel.close already by
    the time the application tries to close the channel.
    Is there a way to say that the channel should remain open even if an
    error occurs in basic.publish?

    Or a way how to get register a channel.close listener, so that I know
    I need to re-open the channel in case I want to continue using it?

    Thanks
    Jiri
  • Matthias Radestock at Nov 3, 2010 at 11:57 am
    Jiri,
    On 03/11/10 11:48, jiri at krutil.com wrote:
    Is there a way to say that the channel should remain open even if an
    error occurs in basic.publish?
    No, all errors in AMQP close either the channel or the connection.
    Or a way how to get register a channel.close listener,
    Yes. See Channel.addShutdownListener et al.
    so that I know I need to re-open the channel in case I want to
    continue using it?
    There is a good chance that anything you do along these lines will be
    racy. Since the errors arrive asynchronously it generally is impossible
    to guarantee that the invocation of a method on a channel won't fail
    with an AlreadyClosedException. So you may want to catch that exception
    and re-open the channel then.


    Regards,

    Matthias.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprabbitmq-discuss @
categoriesrabbitmq
postedNov 3, '10 at 10:08a
activeNov 3, '10 at 11:57a
posts6
users2
websiterabbitmq.com
irc#rabbitmq

2 users in discussion

Matthias Radestock: 3 posts Jiri: 3 posts

People

Translate

site design / logo © 2022 Grokbase