prefetchCount:1 fixes this issue, but i want to pop items in parallel if possible.<br><br>On Sunday, May 5, 2013 3:48:47 PM UTC-7, macmilla...@gmail.com wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div>My Node.js worker crashes (RECONDITION_FAILED - unknown delivery tag) if the following 2 conditions are met:&nbsp;</div><div><br></div><div>1. I start it AFTER the queue have at least 2 messages.&nbsp;</div><div>2. The q.shift() is in an async code.</div><div><br></div><div><a href="http://pastebin.com/uMQJn0Fe" target="_blank">http://pastebin.com/uMQJn0Fe</a> &nbsp;&nbsp;</div><div><br></div><div><div>                
                <div><ol><div><span>// index.js</span></div>
<div><span>var</span> amqp <span>=</span> require<span>(</span><span>'amqp'</span><span>)</span><span>;</span></div>
<div>&nbsp;</div>
<div><span>var</span> connection <span>=</span> <span>null</span><span>;</span></div>
<div>&nbsp;</div>
<div>connection <span>=</span> amqp.<span>createConnection</span><span>(</span><span>{</span> host<span>:</span> <span>'<a href="http://foo.com" target="_blank">foo.com</a>'</span> <span>}</span><span>)</span><span>;</span></div>
<div>&nbsp;</div>
<div>connection.<span>on</span><span>(</span><span>'ready'</span><span>,</span> <span>function</span> <span>(</span><span>)</span> <span>{</span></div>
<div>&nbsp; connection.<span>queue</span><span>(</span><span>'loc'</span><span>,</span> <span>{</span> durable<span>:</span> <span>true</span><span>,</span> autoDelete<span>:</span> <span>false</span><span>}</span><span>,</span> <span>function</span><span>(</span>q<span>)</span> <span>{</span></div>
<div>&nbsp; &nbsp; q.<span>bind</span><span>(</span><span>'main'</span><span>,</span> <span>'loc'</span><span>)</span><span>;</span></div>
<div>&nbsp; &nbsp; q.<span>subscribe</span><span>(</span><span>{</span>ack<span>:</span><span>true</span><span>,</span> prefetchCount<span>:</span> <span>0</span><span>}</span><span>,</span> <span>function</span> <span>(</span>message<span>,</span> headers<span>,</span> deliveryInfo<span>)</span> <span>{</span></div>
<div>&nbsp; &nbsp; &nbsp; console.<span>log</span><span>(</span>message<span>)</span><span>;</span></div>
<div>&nbsp; &nbsp; &nbsp; setTimeout<span>(</span><span>function</span><span>(</span><span>)</span> <span>{</span> q.<span>shift</span><span>(</span><span>)</span><span>;</span> <span>}</span><span>,</span> <span>100</span><span>)</span><span>;</span></div>
<div>&nbsp; &nbsp; <span>}</span><span>)</span><span>;</span></div>
<div>&nbsp; <span>}</span><span>)</span><span>;</span></div>
<div><span>}</span><span>)</span><span>;</span></div>
<div>&nbsp;</div>
<div>my worker crashes only I run it AFTER there are messages <span>in</span> the queue. <span>if</span> I run the worker BEFORE<span>,</span> everything is ok.</div>
<div>&nbsp;</div>
<div><span>I</span> use ab to add <span>2</span> messages to the queue<span>:</span></div>
<div>ab <span>-</span>k <span>-</span>n <span>2</span> <span>-</span>c <span>1</span> <span>-</span>p post<span>-</span>data <span>-</span>T <span>'application/json'</span> foo<span>-</span>api.<span>com</span><span>/</span>publish</div>
<div>&nbsp;</div>
<div>And now run my worker <span>-</span> node index.<span>js</span></div>
<div>here is the outputs<span>:</span></div>
<div>&nbsp;</div>
<div><span>{</span> topic<span>:</span> <span>'loc'</span><span>,</span></div>
<div>&nbsp; sourceCode<span>:</span> <span>'LOC'</span><span>,</span></div>
<div>&nbsp; sourceRecordID<span>:</span> <span>'690599224'</span><span>,</span></div>
<div>&nbsp; sourceField<span>:</span> <span>'Phone'</span><span>,</span></div>
<div>&nbsp; sourceFieldValue<span>:</span> <span>'7572007395'</span><span>,</span></div>
<div>&nbsp; actionCode<span>:</span> <span>'DISP'</span><span>,</span></div>
<div>&nbsp; actionDescription<span>:</span> <span>'Disconnected Phone Number'</span> </div>
<div><span>}</span></div>
<div><span>{</span> topic<span>:</span> <span>'loc'</span><span>,</span></div>
<div>&nbsp; sourceCode<span>:</span> <span>'LOC'</span><span>,</span></div>
<div>&nbsp; sourceRecordID<span>:</span> <span>'690599224'</span><span>,</span></div>
<div>&nbsp; sourceField<span>:</span> <span>'Phone'</span><span>,</span></div>
<div>&nbsp; sourceFieldValue<span>:</span> <span>'7572007395'</span><span>,</span></div>
<div>&nbsp; actionCode<span>:</span> <span>'DISP'</span><span>,</span></div>
<div>&nbsp; actionDescription<span>:</span> <span>'Disconnected Phone Number'</span> </div>
<div><span>}</span></div>
<div>&nbsp;</div>
<div>events.<span>js</span><span>:</span><span>72</span></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; <span>throw</span> er<span>;</span> <span>// Unhandled 'error' event</span></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span>^</span></div>
<div>Error<span>:</span> PRECONDITION_FAILED <span>-</span> unknown delivery tag <span>2</span></div>
<div>&nbsp; &nbsp; at Queue._onMethod <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>1979</span><span>:</span><span>15</span><span>)</span></div>
<div>&nbsp; &nbsp; at Queue.<span>Channel</span>._onChannelMethod <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>1557</span><span>:</span><span>14</span><span>)</span></div>
<div>&nbsp; &nbsp; at Connection._onMethod <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>1088</span><span>:</span><span>28</span><span>)</span></div>
<div>&nbsp; &nbsp; at AMQPParser.<span>parser</span>.<span>onMethod</span> <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>897</span><span>:</span><span>12</span><span>)</span></div>
<div>&nbsp; &nbsp; at AMQPParser._parseMethodFrame <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>451</span><span>:</span><span>10</span><span>)</span></div>
<div>&nbsp; &nbsp; at frameEnd <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>192</span><span>:</span><span>16</span><span>)</span></div>
<div>&nbsp; &nbsp; at frame <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>177</span><span>:</span><span>14</span><span>)</span></div>
<div>&nbsp; &nbsp; at AMQPParser.<span>header</span> <span>[</span>as parse<span>]</span> <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>163</span><span>:</span><span>14</span><span>)</span></div>
<div>&nbsp; &nbsp; at AMQPParser.<span>execute</span> <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>236</span><span>:</span><span>21</span><span>)</span></div>
<div>&nbsp; &nbsp; at Connection.<span>&lt;</span>anonymous<span>&gt;</span> <span>(</span><span>/</span>Users<span>/</span>ogolan<span>/</span>projects<span>/</span>quai<span>-</span>l<wbr>oc<span>/</span>worker<span>/</span>node_modules<span>/</span>amqp<span>/</span>am<wbr>qp.<span>js</span><span>:</span><span>935</span><span>:</span><span>14</span><span>)</span></div>
</ol></div></div></div><div><br></div><div><br></div><div><br></div><div>any ideas?</div><div><br></div></blockquote>