gmr / rabbitpy

A pure python, thread-safe, minimalistic and pythonic RabbitMQ client library
http://rabbitpy.readthedocs.org
BSD 3-Clause "New" or "Revised" License
243 stars 58 forks source link

Message bodies sometimes gets mixed up when publisher confirms are enabled #53

Closed Gyllsdorff closed 5 years ago

Gyllsdorff commented 9 years ago

I have a queue with messages with a json string body and a few headers.

When I enabled enable_publisher_confirms I suddenly got a lot of json.loads(message.body.decode()) errors. When I dumped the message contents I noticed that two message bodies have been concatenated.

When I removed enable_publisher_confirms the problem disappears.

with connection.channel() as channel:
    channel.enable_publisher_confirms()
    for message in Queue(channel, 'foo'):   
        body = message.body.decode()
        json.loads(body)

This is a short dev script so I never do message.ack(). Can that be what triggers this bug?

gmr commented 9 years ago

It's an odd edge case. You're not publishing, but you're enabling publisher confirms. I'll have to recreate and see if I can trace down where things are going awry. I'm not quite sure what could cause that.

gmr commented 9 years ago

I've not been able to reproduce this with your example, with an ack or without.

I'm wondering if your example is not complete and perhaps you are publishing in the consumer?

Also as a FYI you should be able to just do message.json() to get the JSON body of a message.

gmr commented 9 years ago

I was not able to confirm this. In my latest test, I tried republishing the message that was being consumed and I was still not able to reproduce.

I did however find an issue with Basic.Nack support out of the ticket. Can you provide sample code that proves out the issue?

eandersson commented 9 years ago

I have seen this happen once as well in my own library (based on pamqp). I was never able to re-produce it.