Skip to content

x-death count not incremented when message expired #10709

@bmflynn

Description

@bmflynn

Describe the bug

When a message with an expiration and an existing x-death (same queue and reason) is re-published to a classic queue with a dead-letter exchange the x-death['count'] is not incremented.

Reproduction steps

import os
import time
from collections import namedtuple
from pprint import pprint

from pika import BasicProperties, BlockingConnection, URLParameters

Msg = namedtuple("Msg", ["method", "properties", "body"])

amqpurl = os.environ["AMQPURL"]
exchange = "amq.topic"

start_queue = "start_queue"
dlx_exchange = "errors"
error_queue = "dead_letters"
routing_key = "test_retries"

data = "XXX"

conn = BlockingConnection(URLParameters(amqpurl))
ch = conn.channel()

ch.exchange_declare(dlx_exchange, "topic")
ch.queue_declare(error_queue)
ch.queue_bind(error_queue, dlx_exchange, "#")

ch.queue_declare(start_queue, arguments={"x-dead-letter-exchange": dlx_exchange})
ch.queue_bind(start_queue, exchange, routing_key)

print(f"first publish {exchange=} {routing_key=} {data=}")
ch.basic_publish(exchange, routing_key, data, properties=BasicProperties(expiration="1000"))


# Wait for message to error out
print("waiting")
time.sleep(5)

first = Msg(*ch.basic_get(error_queue))
ch.basic_ack(first.method.delivery_tag)
assert first.method is not None, f"No message available {error_queue=}"
assert len(first.properties.headers["x-death"]) == 1
pprint(first.properties.headers)
assert first.properties.headers["x-death"][0]["count"] == 1

print("Second publish")
# Publish the message data again with the x-death headers having count=1
first.properties.expiration = "1000"
ch.basic_publish(exchange, routing_key, data, properties=first.properties)

# Wait for message to expire again
print("waiting")
time.sleep(5)
second = Msg(*ch.basic_get(error_queue))
ch.basic_ack(second.method.delivery_tag)
assert len(second.properties.headers["x-death"]) == 1
pprint(second.properties.headers)

ch.close()
conn.close()

Expected behavior

x-death['count'] should be incremented for each death with matching reason and queue per docs.

Additional context

I tested on versions 3.9, 3.10, 3.11, 3.12, & 3.13 using the rabbitmq:<ver>-management docker image and it only fails to increment on 3.13.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions