Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to publish on a closed channel results in broad exception type RuntimeError #63

Closed
phijor opened this issue Nov 6, 2019 · 5 comments

Comments

@phijor
Copy link

phijor commented Nov 6, 2019

Hi,

we are working on an application that, through aio-pika, uses aiormq. While dealing with some issues caused by unreliable network conditions, we noticed that trying to publish on a channel that has been closed results in a rather broad RuntimeError, raised here:

raise RuntimeError('%r closed' % self)

Below is a typical stack trace for when this happens, starting at a call to aio_pika.Exchange.publish():

Traceback (most recent call last):
  <snip>
  ...
  </snip>
  File "/<our_project>/source.py", line 106, in _send
    await self.data_exchange.publish(msg, routing_key=metric, mandatory=False)
  File "/<venv>/lib/python3.7/site-packages/aio_pika/exchange.py", line 200, in publish
    ), timeout=timeout
  File "/usr/lib64/python3.7/asyncio/tasks.py", line 414, in wait_for
    return await fut
  File "/<venv>/lib/python3.7/site-packages/aiormq/channel.py", line 426, in basic_publish
    async with self.lock:
  File "/<venv>/lib/python3.7/site-packages/aiormq/channel.py", line 77, in lock
    raise RuntimeError('%r closed' % self)
RuntimeError: <Channel: "1"> closed

We are afraid that, when writing error handling code for this condition, catching RuntimeError might accidentally catch other errors, too.

Would it be possible to raise a more descriptive exception, of distinct type? The exception type might subclass RuntimeError as to not break code that catches that.

@decaz
Copy link
Contributor

decaz commented Nov 6, 2019

Also thought about it. Perhaps existing ChannelClosed exception would fit..

@mosquito
Copy link
Owner

Fixed in #65. and aiormq==3.1.0

@mosquito
Copy link
Owner

Thank you for this issue and sorry for the delayed reply. I hope I released what are you wanted :-)

Please close this issue if this enough.

@decaz
Copy link
Contributor

decaz commented Nov 14, 2019

I remember about need of backward compatibility, but if inherit new exception from AMQPChannelError then it would be possible to easily catch any exception raised by aiormq by simply handling AMQPError.

@phijor
Copy link
Author

phijor commented Nov 18, 2019

I like @decaz's idea of having a single exception to catch, but right now having ChannelInvalidStateError is good enough, as it cover most (all?) of our use cases.

Thank you :)

Now the only thing that is needed is a release of aio-pika that includes this fix. I see that since mosquito/aio-pika@6498575, it already uses aiormq~=3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants