Skip to content

Commit

Permalink
Handle non-waiter condition on close better
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfix committed Aug 3, 2019
1 parent b9777a3 commit c65722d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions asyncamqp/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _set_waiter(self, rpc_name):
def _get_waiter(self, rpc_name):
fut = self._futures.pop(rpc_name, None)
if not fut:
raise exceptions.SynchronizationError("Call %s didn't set a waiter" % rpc_name)
raise exceptions.SynchronizationError("Call %r didn't set a waiter" % rpc_name)
return fut

@property
Expand Down Expand Up @@ -291,7 +291,12 @@ async def close(self, reply_code=0, reply_text="Normal Shutdown"):
)

async def close_ok(self, frame):
await self._get_waiter('close').set_result(True)
try:
w = self._get_waiter('close')
except asyncamqp.exceptions.SynchronizationError:
pass
else:
await w.set_result(True)
logger.info("Channel closed")
self.protocol.release_channel_id(self.channel_id)

Expand Down
6 changes: 5 additions & 1 deletion asyncamqp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,14 @@ async def _reader_loop(self, done):
# going for now (need to process the close-OK
# message). Thus we start a new task that
# raises the actual error, somewhat later.
if self._nursery is None:
raise

async def owch(exc):
await anyio.sleep(0)
await anyio.sleep(0.01)
raise exc

logger.error("Queue",repr(exc))
await self._nursery.spawn(owch, exc)

except TimeoutError:
Expand Down

0 comments on commit c65722d

Please sign in to comment.