[rabbitmq-discuss] Race condition when acknowledging messages?
Simon MacMullen
simon at rabbitmq.com
Tue Jun 17 09:22:38 BST 2014
On 16/06/2014 21:57, Roger Hu wrote:
> 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
> sent is handled by the rabbit_writer process.
>
> ok = rabbit_writer:send_command(
> WriterPid,
> #'basic.get_ok'{delivery_tag = DeliveryTag,
> redelivered = Redelivered,
> exchange = ExchangeName#resource.name,
> routing_key = RoutingKey,
> message_count = MessageCount},
> Content),
> State1 = monitor_delivering_queue(NoAck, QPid, QName, State),
> {noreply, record_sent(none, not(NoAck), Msg, State1)};
>
>
> 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:
>
> true -> queue:in({DeliveryTag, ConsumerTag, {QPid, MsgId}},
> UAMQ);
Yes.
> Is it possible there is a race condition in which the delivery tag
> received by the client has yet to be recorded?
But no. Not in any way that makes any difference, anyway.
The point is that the channel can deliver the message and then record
the ack, because it won't respond to any further messages from the
outside world until it has returned from handle_cast(), by which time
the ack is recorded.
So I suspect that there is an issue in your code I'm afraid.
Cheers, Simon
More information about the rabbitmq-discuss
mailing list