ebin123456 / py-amqplib

Automatically exported from code.google.com/p/py-amqplib
GNU Lesser General Public License v2.1
0 stars 0 forks source link

calling basic_cancel on a closed connection is unsafe #44

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Which version of amqplib are you using?
0.6.1
Have you checked to see if there is a newer version in the "Featured
Downloads" section of the front page of this project?

Yes, but code inspection leads me to believe this is still an issue

Which broker are you using (RabbitMQ?) which version?
yes (rabbit), not sure of version
Which version of Python?
2.7
What steps will reproduce the problem?
1. create a channel
2. start consuming
3. kill rabbit
4. have a basic_cancel in a try:finally: around your consumer loop

What is the expected output? What do you see instead?

I'd expect the basic_cancel to just do nothing on a closed connection (or 
possibly raise an explicit exception).

What we see is captured here:
https://bugs.launchpad.net/python-oops-amqp/+bug/884539
"Traceback (most recent call last):
  File "bin/amqp2disk", line 49, in <module>
    oopstools.scripts.amqp2disk.main()
  File "/srv/lp-oops.canonical.com/cgi-bin/lpoops/src/oopstools/scripts/amqp2disk.py", line 113, in main
    receiver.run_forever()
  File "/srv/lp-oops.canonical.com/cgi-bin/lpoops/eggs/oops_amqp-0.0.3-py2.6.egg/oops_amqp/receiver.py", line 86, in run_forever
    self._run_forever()
  File "/srv/lp-oops.canonical.com/cgi-bin/lpoops/eggs/oops_amqp-0.0.3-py2.6.egg/oops_amqp/receiver.py", line 112, in _run_forever
    self.channel.basic_cancel(self.consume_tag)
  File "/srv/lp-oops.canonical.com/cgi-bin/lpoops/eggs/amqplib-0.6.1-py2.6.egg/amqplib/client_0_8/channel.py", line 1702, in basic_cancel
    self._send_method((60, 30), args)
  File "/srv/lp-oops.canonical.com/cgi-bin/lpoops/eggs/amqplib-0.6.1-py2.6.egg/amqplib/client_0_8/abstract_channel.py", line 69, in _send_method
    self.connection.method_writer.write_method(self.channel_id,
AttributeError: 'NoneType' object has no attribute 'method_writer'
"

Please provide any additional information below.
We've put a if self.channel.is_open: guard around the call to basic_cancel, but 
it would be nice to have fire-and-forget here, as it seems like an obvious 
idiom to be cancelling consumption in a try:finally:

Original issue reported on code.google.com by robert.c...@gmail.com on 1 Nov 2011 at 3:54