Skip to content

Commit 18e80d6

Browse files
committed
ignore amqp:resource-deleted when closing management sender and receive
This is done to fix a problem where a queue is deleted before the link is closed, this caused the test tests/asyncio/test_publisher.py::test_connection_context_manager_async to be flaky format fix
1 parent 10b988c commit 18e80d6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

rabbitmq_amqp_python_client/management.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
BlockingConnection,
1919
BlockingReceiver,
2020
BlockingSender,
21+
LinkDetached,
2122
)
2223
from .queues import (
2324
ClassicQueueSpecification,
@@ -92,10 +93,22 @@ def close(self) -> None:
9293
Closes both sender and receiver if they exist.
9394
"""
9495
logger.debug("Closing Sender and Receiver")
95-
if self._sender is not None:
96-
self._sender.close()
97-
if self._receiver is not None:
98-
self._receiver.close()
96+
97+
if self._sender:
98+
try:
99+
self._sender.close()
100+
except LinkDetached as e:
101+
# avoid raising exception if the queue is deleted before closing the link
102+
if e.condition and e.condition != "amqp:resource-deleted":
103+
raise
104+
105+
if self._receiver:
106+
try:
107+
self._receiver.close()
108+
except LinkDetached as e:
109+
if e.condition and e.condition != "amqp:resource-deleted":
110+
raise
111+
pass
99112

100113
def request(
101114
self,

0 commit comments

Comments
 (0)