<div dir="ltr">We are running RabbitMQ v3.3.1 and librabbitmq v1.5.2 and have noticed that our client is periodically getting these exceptions:<div><br></div><div><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"><span class="t">ChannelError</span>:</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">channel</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">error</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">406</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">, </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"><span class="t">message</span>:</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"><span class="t">PRECONDITION</span>_<span class="t">FAILED</span></span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">-</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">unknown</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">delivery</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t" style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;">tag</span><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"> </span><span class="t a" style="background-color: rgb(253, 233, 168); border-top-width: 4px; border-top-style: solid; border-top-color: rgb(253, 233, 168); border-bottom-width: 4px; border-bottom-style: solid; border-bottom-color: rgb(253, 233, 168); color: rgb(50, 73, 106); font-family: 'Droid Sans Mono', Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre-wrap;"><span class="t">704117</span></span><br></div><div><br></div><div>We have a dedicated separate connection and channel setup to receive the message and ack it back immediately.     We notice that the delivery tag of the same as the one we're</div><div>trying to acknowledge back, so this tag ID appears to be consistent and one that RMQ should know about.  However, it appears to trigger a PRECONDITION_FAILED, making us think</div><div>we made a duplicate ACK acknowledgment somewhere.  We have placed logging statements to centralize all message acknowledgments and only see one ACK, confirming our belief</div><div>that it is a single ACK being made.</div><div><br></div><div>We noticed in this code (https://github.com/rabbitmq/rabbitmq-server/blob/master/src/rabbit_channel.erl#L741-750) that the record of the note being</div><div>sent is handled by the rabbit_writer process.</div><div><br></div><div><div><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); line-height: 18px;"><div class="line" id="LC741" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">            <span class="n" style="box-sizing: border-box;">ok</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nn" style="box-sizing: border-box; color: rgb(85, 85, 85);">rabbit_writer</span><span class="p" style="box-sizing: border-box;">:</span><span class="nf" style="box-sizing: border-box; color: rgb(153, 0, 0); font-weight: bold;">send_command</span><span class="p" style="box-sizing: border-box;">(</span></div><div class="line" id="LC742" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                   <span class="nv" style="box-sizing: border-box; color: teal;">WriterPid</span><span class="p" style="box-sizing: border-box;">,</span></div><div class="line" id="LC743" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                   <span class="nl" style="box-sizing: border-box;">#'basic.get_ok'</span><span class="p" style="box-sizing: border-box;">{</span><span class="n" style="box-sizing: border-box;">delivery_tag</span>  <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">DeliveryTag</span><span class="p" style="box-sizing: border-box;">,</span></div><div class="line" id="LC744" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                                   <span class="n" style="box-sizing: border-box;">redelivered</span>   <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">Redelivered</span><span class="p" style="box-sizing: border-box;">,</span></div><div class="line" id="LC745" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                                   <span class="n" style="box-sizing: border-box;">exchange</span>      <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">ExchangeName</span><span class="nl" style="box-sizing: border-box;">#resource.name</span><span class="p" style="box-sizing: border-box;">,</span></div><div class="line" id="LC746" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                                   <span class="n" style="box-sizing: border-box;">routing_key</span>   <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">RoutingKey</span><span class="p" style="box-sizing: border-box;">,</span></div><div class="line" id="LC747" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                                   <span class="n" style="box-sizing: border-box;">message_count</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">MessageCount</span><span class="p" style="box-sizing: border-box;">},</span></div><div class="line" id="LC748" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                   <span class="nv" style="box-sizing: border-box; color: teal;">Content</span><span class="p" style="box-sizing: border-box;">),</span></div><div class="line" id="LC749" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">            <span class="nv" style="box-sizing: border-box; color: teal;">State1</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">monitor_delivering_queue</span><span class="p" style="box-sizing: border-box;">(</span><span class="nv" style="box-sizing: border-box; color: teal;">NoAck</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nv" style="box-sizing: border-box; color: teal;">QPid</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nv" style="box-sizing: border-box; color: teal;">QName</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nv" style="box-sizing: border-box; color: teal;">State</span><span class="p" style="box-sizing: border-box;">),</span></div><div class="line" id="LC750" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">            <span class="p" style="box-sizing: border-box;">{</span><span class="n" style="box-sizing: border-box;">noreply</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">record_sent</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">none</span><span class="p" style="box-sizing: border-box;">,</span> <span class="ow" style="box-sizing: border-box; font-weight: bold;">not</span><span class="p" style="box-sizing: border-box;">(</span><span class="nv" style="box-sizing: border-box; color: teal;">NoAck</span><span class="p" style="box-sizing: border-box;">),</span> <span class="nv" style="box-sizing: border-box; color: teal;">Msg</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nv" style="box-sizing: border-box; color: teal;">State1</span><span class="p" style="box-sizing: border-box;">)};</span></div></pre></div></div><div><br></div><div> However, the delivery tag information appears to get record later in https://github.com/rabbitmq/rabbitmq-server/blob/master/src/rabbit_channel.erl#L1380-1384:</div><div><br></div><div><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; color: rgb(51, 51, 51); line-height: 18px;"><div class="line" id="LC1381" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">   <span class="n" style="box-sizing: border-box;">true</span>  <span class="o" style="box-sizing: border-box; font-weight: bold;">-></span> <span class="nn" style="box-sizing: border-box; color: rgb(85, 85, 85);">queue</span><span class="p" style="box-sizing: border-box;">:</span><span class="nf" style="box-sizing: border-box; color: rgb(153, 0, 0); font-weight: bold;">in</span><span class="p" style="box-sizing: border-box;">({</span><span class="nv" style="box-sizing: border-box; color: teal;">DeliveryTag</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nv" style="box-sizing: border-box; color: teal;">ConsumerTag</span><span class="p" style="box-sizing: border-box;">,</span> <span class="p" style="box-sizing: border-box;">{</span><span class="nv" style="box-sizing: border-box; color: teal;">QPid</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nv" style="box-sizing: border-box; color: teal;">MsgId</span><span class="p" style="box-sizing: border-box;">}},</span></div><div class="line" id="LC1382" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);">                                  <span class="nv" style="box-sizing: border-box; color: teal;">UAMQ</span><span class="p" style="box-sizing: border-box;">);</span></div></pre></div><div><br></div><div><div>Our current workaround is to delay acknowledging the message instead of trying to ack it right away.  The problem shows up intermittently, possibly when there are large queue volumes on the RMQ box and possibly when we start to queue up 50-60K unacknowledged messages, which may cause issues for the delivery tag to be added to the unacked list (UAMQ).</div><div><span style="font-size: 13px;"><br></span></div><div><span style="font-size: 13px;">Is it possible there is a race condition in which the delivery tag received by the client has yet to be recorded?    </span><span style="font-size: 13px;">Again, the problem happens intermittently but would like to suggest changing the code to record the delivery tag (in record_sent() before dispatching rabbit_writer.  </span></div></div><div><br></div><div>Would appreciate any thoughts about changing the code to add the message before responding back to the writer.</div><div><br></div><div>Thanks,</div><div><br></div><div>Roger</div></div>