Skip to content

Commit 181aec8

Browse files
committed
fix: RobustChannel should not reopen after close() call
1 parent 1a8d5b6 commit 181aec8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

aio_pika/robust_channel.py

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ async def _on_close(
121121

122122
return exc
123123

124+
async def close(
125+
self,
126+
exc: Optional[aiormq.abc.ExceptionType] = None,
127+
) -> None:
128+
# Avoid recovery when channel is explicitely closed using this method
129+
self.__restored.clear()
130+
await super().close(exc)
131+
124132
async def reopen(self) -> None:
125133
await super().reopen()
126134
await self.reopen_callbacks()

tests/test_amqp_robust.py

+16
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,25 @@ async def test_channel_is_ready_after_close_and_reopen(self, connection):
110110
channel: RobustChannel = await connection.channel() # type: ignore
111111
await channel.ready()
112112
await channel.close()
113+
assert channel.is_closed is True
114+
113115
await channel.reopen()
114116
await asyncio.wait_for(channel.ready(), timeout=1)
115117

118+
assert channel.is_closed is False
119+
120+
async def test_channel_can_be_closed(self, connection):
121+
channel: RobustChannel = await connection.channel() # type: ignore
122+
await channel.ready()
123+
await channel.close()
124+
125+
assert channel.is_closed
126+
127+
with pytest.raises(asyncio.TimeoutError):
128+
await asyncio.wait_for(channel.ready(), timeout=1)
129+
130+
assert channel.is_closed
131+
116132

117133
class TestCaseAmqpNoConfirmsRobust(TestCaseAmqpNoConfirms):
118134
pass

0 commit comments

Comments
 (0)