<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Victor,<br>
    <br>
    Thanks for reporting this, and for providing a test case! I've filed
    a bug to fix it and hopefully it'll be included in the next release.<br>
    <br>
    Tim<br>
    <br>
    On 03/27/2013 06:26 AM, Victor Boivie wrote:
    <blockquote
cite="mid:CAJ9O1RrG1CCZbh5eoWgQswaZur9yGj3FOdSSXHqasBjucVSZsA@mail.gmail.com"
      type="cite">
      <div dir="ltr">I have been having some problems with the
        java-rabbitmq-client when stress testing it. I frequently get
        "COMMAND_INVALID - second 'channel.open' seen", which eventually
        closes the connection (not just the channel).
        <div>
          <br>
        </div>
        <div style="">It seems that there is a race condition when
          channels are closed asynchronously (due to errors), and
          created in other threads. The channel that is closed (by the
          server) doesn't seem to be fully closed before another thread
          can try to open a channel with the same number.</div>
        <div style=""><br>
        </div>
        <div style="">The code to reproduce it is at&nbsp;<a
            moz-do-not-send="true"
            href="https://github.com/boivie/rmq-stress-test">https://github.com/boivie/rmq-stress-test</a></div>
        <div style=""><br>
        </div>
        <div style="">A possible fix is below.</div>
        <div style=""><br>
        </div>
        <div style="">Thanks,</div>
        <div style="">Victor</div>
        <div style=""><br>
        </div>
        <div style="">
          <div>From 213cf8ef15a759985bc9dd74496548236b5160f2 Mon Sep 17
            00:00:00 2001</div>
          <div>From: Victor Boivie &lt;<a moz-do-not-send="true"
              href="mailto:victor@boivie.com">victor@boivie.com</a>&gt;</div>
          <div>Date: Wed, 27 Mar 2013 07:22:04 +0100</div>
          <div>Subject: [PATCH] Fix race-condition of asynchronously
            closed channels</div>
          <div><br>
          </div>
          <div>When a channel is closed from the server side due to
            errors we</div>
          <div>
            have to send CloseOk before we can make it available for
            allocation</div>
          <div>again. If not, we risk handing it out to a client which
            will open it</div>
          <div>when it's not yet fully closed, which results in a</div>
          <div>
            "COMMAND_INVALID - second 'channel.open' seen".</div>
          <div><br>
          </div>
          <div>diff --git a/src/com/rabbitmq/client/impl/ChannelN.java
            b/src/com/rabbitmq/client/impl/ChannelN.java</div>
          <div>index 18e4f6a..9fe11c3 100644</div>
          <div>--- a/src/com/rabbitmq/client/impl/ChannelN.java</div>
          <div>+++ b/src/com/rabbitmq/client/impl/ChannelN.java</div>
          <div>@@ -471,7 +471,6 @@ public class ChannelN extends
            AMQChannel implements com.rabbitmq.client.Channel</div>
          <div>&nbsp; &nbsp; &nbsp;}</div>
          <div>&nbsp;</div>
          <div>&nbsp; &nbsp; &nbsp;private void asyncShutdown(Command command) throws
            IOException {</div>
          <div>- &nbsp; &nbsp; &nbsp; &nbsp;releaseChannel();</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShutdownSignalException signal = new
            ShutdownSignalException(false,</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; false,</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command,</div>
          <div>@@ -484,6 +483,7 @@ public class ChannelN extends
            AMQChannel implements com.rabbitmq.client.Channel</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notifyOutstandingRpc(signal);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>
          <div>+ &nbsp; &nbsp; &nbsp; &nbsp;releaseChannel();</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notifyListeners();</div>
          <div>&nbsp; &nbsp; &nbsp;}</div>
          <div>&nbsp;</div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
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="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>