From 1ba9dc6eb65cd57889c8f459ba953e14e82d157e Mon Sep 17 00:00:00 2001 From: Zachary Ware Date: Wed, 8 Mar 2023 14:14:58 -0600 Subject: [PATCH] basic_publish: Don't create drain_future until use When the future is created before the lock is acquired, an asyncio warning about "Future exception was never retrieved" can be logged if connection is lost while waiting for the lock. --- aiormq/channel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiormq/channel.py b/aiormq/channel.py index 4f1cbe0..b0a3649 100644 --- a/aiormq/channel.py +++ b/aiormq/channel.py @@ -628,7 +628,6 @@ async def basic_publish( wait: bool = True, ) -> Optional[ConfirmationFrameType]: _check_routing_key(routing_key) - drain_future = self.create_future() if wait else None countdown = Countdown(timeout=timeout) publish_frame = spec.Basic.Publish( @@ -677,6 +676,7 @@ async def basic_publish( body_frames = [publish_frame, content_header] body_frames += self._split_body(body) + drain_future = self.create_future() if wait else None await countdown( self.write_queue.put( ChannelFrame.marshall(