<div>My Node.js worker crashes (RECONDITION_FAILED - unknown delivery tag) if the following 2 conditions are met: </div><div><br></div><div>1. I start it AFTER the queue have at least 2 messages. </div><div>2. The q.shift() is in an async code.</div><div><br></div><div>http://pastebin.com/uMQJn0Fe </div><div><br></div><div><div id="selectable">                
                <div class="javascript"><ol><div class="de1"><span class="co1">// index.js</span></div>
<div class="de2"><span class="kw1">var</span> amqp <span class="sy0">=</span> require<span class="br0">(</span><span class="st0">'amqp'</span><span class="br0">)</span><span class="sy0">;</span></div>
<div class="de1"> </div>
<div class="de2"><span class="kw1">var</span> connection <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></div>
<div class="de1"> </div>
<div class="de2">connection <span class="sy0">=</span> amqp.<span class="me1">createConnection</span><span class="br0">(</span><span class="br0">{</span> host<span class="sy0">:</span> <span class="st0">'foo.com'</span> <span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></div>
<div class="de1"> </div>
<div class="de2">connection.<span class="me1">on</span><span class="br0">(</span><span class="st0">'ready'</span><span class="sy0">,</span> <span class="kw1">function</span> <span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span></div>
<div class="de1"> connection.<span class="me1">queue</span><span class="br0">(</span><span class="st0">'loc'</span><span class="sy0">,</span> <span class="br0">{</span> durable<span class="sy0">:</span> <span class="kw2">true</span><span class="sy0">,</span> autoDelete<span class="sy0">:</span> <span class="kw2">false</span><span class="br0">}</span><span class="sy0">,</span> <span class="kw1">function</span><span class="br0">(</span>q<span class="br0">)</span> <span class="br0">{</span></div>
<div class="de2"> q.<span class="me1">bind</span><span class="br0">(</span><span class="st0">'main'</span><span class="sy0">,</span> <span class="st0">'loc'</span><span class="br0">)</span><span class="sy0">;</span></div>
<div class="de1"> q.<span class="me1">subscribe</span><span class="br0">(</span><span class="br0">{</span>ack<span class="sy0">:</span><span class="kw2">true</span><span class="sy0">,</span> prefetchCount<span class="sy0">:</span> <span class="nu0">0</span><span class="br0">}</span><span class="sy0">,</span> <span class="kw1">function</span> <span class="br0">(</span>message<span class="sy0">,</span> headers<span class="sy0">,</span> deliveryInfo<span class="br0">)</span> <span class="br0">{</span></div>
<div class="de2"> console.<span class="me1">log</span><span class="br0">(</span>message<span class="br0">)</span><span class="sy0">;</span></div>
<div class="de1"> setTimeout<span class="br0">(</span><span class="kw1">function</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> q.<span class="me1">shift</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span> <span class="br0">}</span><span class="sy0">,</span> <span class="nu0">100</span><span class="br0">)</span><span class="sy0">;</span></div>
<div class="de2"> <span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></div>
<div class="de1"> <span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></div>
<div class="de2"><span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></div>
<div class="de1"> </div>
<div class="de2">my worker crashes only I run it AFTER there are messages <span class="kw1">in</span> the queue. <span class="kw1">if</span> I run the worker BEFORE<span class="sy0">,</span> everything is ok.</div>
<div class="de1"> </div>
<div class="de2"><span class="me1">I</span> use ab to add <span class="nu0">2</span> messages to the queue<span class="sy0">:</span></div>
<div class="de1">ab <span class="sy0">-</span>k <span class="sy0">-</span>n <span class="nu0">2</span> <span class="sy0">-</span>c <span class="nu0">1</span> <span class="sy0">-</span>p post<span class="sy0">-</span>data <span class="sy0">-</span>T <span class="st0">'application/json'</span> foo<span class="sy0">-</span>api.<span class="me1">com</span><span class="sy0">/</span>publish</div>
<div class="de2"> </div>
<div class="de1">And now run my worker <span class="sy0">-</span> node index.<span class="me1">js</span></div>
<div class="de2">here is the outputs<span class="sy0">:</span></div>
<div class="de1"> </div>
<div class="de2"><span class="br0">{</span> topic<span class="sy0">:</span> <span class="st0">'loc'</span><span class="sy0">,</span></div>
<div class="de1"> sourceCode<span class="sy0">:</span> <span class="st0">'LOC'</span><span class="sy0">,</span></div>
<div class="de2"> sourceRecordID<span class="sy0">:</span> <span class="st0">'690599224'</span><span class="sy0">,</span></div>
<div class="de1"> sourceField<span class="sy0">:</span> <span class="st0">'Phone'</span><span class="sy0">,</span></div>
<div class="de2"> sourceFieldValue<span class="sy0">:</span> <span class="st0">'7572007395'</span><span class="sy0">,</span></div>
<div class="de1"> actionCode<span class="sy0">:</span> <span class="st0">'DISP'</span><span class="sy0">,</span></div>
<div class="de2"> actionDescription<span class="sy0">:</span> <span class="st0">'Disconnected Phone Number'</span> </div>
<div class="de1"><span class="br0">}</span></div>
<div class="de2"><span class="br0">{</span> topic<span class="sy0">:</span> <span class="st0">'loc'</span><span class="sy0">,</span></div>
<div class="de1"> sourceCode<span class="sy0">:</span> <span class="st0">'LOC'</span><span class="sy0">,</span></div>
<div class="de2"> sourceRecordID<span class="sy0">:</span> <span class="st0">'690599224'</span><span class="sy0">,</span></div>
<div class="de1"> sourceField<span class="sy0">:</span> <span class="st0">'Phone'</span><span class="sy0">,</span></div>
<div class="de2"> sourceFieldValue<span class="sy0">:</span> <span class="st0">'7572007395'</span><span class="sy0">,</span></div>
<div class="de1"> actionCode<span class="sy0">:</span> <span class="st0">'DISP'</span><span class="sy0">,</span></div>
<div class="de2"> actionDescription<span class="sy0">:</span> <span class="st0">'Disconnected Phone Number'</span> </div>
<div class="de1"><span class="br0">}</span></div>
<div class="de2"> </div>
<div class="de1">events.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">72</span></div>
<div class="de2"> <span class="kw1">throw</span> er<span class="sy0">;</span> <span class="co1">// Unhandled 'error' event</span></div>
<div class="de1"> <span class="sy0">^</span></div>
<div class="de2">Error<span class="sy0">:</span> PRECONDITION_FAILED <span class="sy0">-</span> unknown delivery tag <span class="nu0">2</span></div>
<div class="de1"> at Queue._onMethod <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">1979</span><span class="sy0">:</span><span class="nu0">15</span><span class="br0">)</span></div>
<div class="de2"> at Queue.<span class="me1">Channel</span>._onChannelMethod <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">1557</span><span class="sy0">:</span><span class="nu0">14</span><span class="br0">)</span></div>
<div class="de1"> at Connection._onMethod <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">1088</span><span class="sy0">:</span><span class="nu0">28</span><span class="br0">)</span></div>
<div class="de2"> at AMQPParser.<span class="me1">parser</span>.<span class="me1">onMethod</span> <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">897</span><span class="sy0">:</span><span class="nu0">12</span><span class="br0">)</span></div>
<div class="de1"> at AMQPParser._parseMethodFrame <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">451</span><span class="sy0">:</span><span class="nu0">10</span><span class="br0">)</span></div>
<div class="de2"> at frameEnd <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">192</span><span class="sy0">:</span><span class="nu0">16</span><span class="br0">)</span></div>
<div class="de1"> at frame <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">177</span><span class="sy0">:</span><span class="nu0">14</span><span class="br0">)</span></div>
<div class="de2"> at AMQPParser.<span class="me1">header</span> <span class="br0">[</span>as parse<span class="br0">]</span> <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">163</span><span class="sy0">:</span><span class="nu0">14</span><span class="br0">)</span></div>
<div class="de1"> at AMQPParser.<span class="me1">execute</span> <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">236</span><span class="sy0">:</span><span class="nu0">21</span><span class="br0">)</span></div>
<div class="de2"> at Connection.<span class="sy0"><</span>anonymous<span class="sy0">></span> <span class="br0">(</span><span class="sy0">/</span>Users<span class="sy0">/</span>ogolan<span class="sy0">/</span>projects<span class="sy0">/</span>quai<span class="sy0">-</span>loc<span class="sy0">/</span>worker<span class="sy0">/</span>node_modules<span class="sy0">/</span>amqp<span class="sy0">/</span>amqp.<span class="me1">js</span><span class="sy0">:</span><span class="nu0">935</span><span class="sy0">:</span><span class="nu0">14</span><span class="br0">)</span></div>
</ol></div></div></div><div><br></div><div><br></div><div><br></div><div>any ideas?</div><div><br></div>