celery / kombu

Messaging library for Python.
http://kombu.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
2.89k stars 930 forks source link

Closed connection and with statement blows up #690

Closed emiel closed 6 years ago

emiel commented 7 years ago

The following code will blow up (see gist) when the connection is closed from the server end. I'm using RabbitMQ and force the closing of the connection from the RabbitMQ console.

    with Connection(broker_url) as conn:
        try:
            SomeChildClassOfConsumerMixin(conn).run()
        except KeyboardInterrupt:
            print("bye bye")

https://gist.github.com/emiel/a4aa857bd4080a1032edc6bb2576f850

Using kombu==4.0.2

https://github.com/celery/kombu/blob/master/kombu/messaging.py#L438

The code (messaging.py#L438) assumes the channel always has a connection though in this case connection has been set to None.

Let me know if you need more info. Thanks!

eavictor commented 7 years ago

Hi emiel,

I also have this issue since kombu==4.0.1 Backend is RabbitMQ 3.6.9(CloudAMQP)

https://gist.github.com/eavictor/ee7856581619ac60643b57987b7ed580 This example works good after I rolled back to kombu==4.0.0 and amqp==2.1.3

1. Setup a RabbitMQ (or use CloudAMQP)

2. Change AMQP broker URL
    Line.59 in mq_kombu_rpc_server.py
    Line.72 in mq_kombu_rpc_client.py

3. execute mq_kombu_rpc_server.py

4. execute mq_kombu_rpc_client.py and BOOM!!

kombu==4.0.1 amqp==2.1.3 Which is same as the issue you bumped into

  File "C:/Users/eavictor/PycharmProjects/MQ_Example/mq_kombu_rpc_client.py", line 72, in <module>
    main('amqps://------remove__RabbitMQ_broker_URL------')
  File "C:/Users/eavictor/PycharmProjects/MQ_Example/mq_kombu_rpc_client.py", line 66, in main
    response = fibonacci_rpc.call(num)
  File "C:/Users/eavictor/PycharmProjects/MQ_Example/mq_kombu_rpc_client.py", line 57, in call
    self.connection.drain_events(timeout=300)
  File "C:\Users\eavictor\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\messaging.py", line 438, in __exit__
    conn_errors = self.channel.connection.client.connection_errors
AttributeError: 'NoneType' object has no attribute 'client'

Note: amqp==2.1.4 is broken on Windows https://github.com/celery/py-amqp/issues/135 [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call

Memo: Can't test kombu 4.0.2 now (no Linux or MAC until I'm home) Change messaging.py Line 438 from if channel: to if channel.connection:

ApplicationInterfacesRNS commented 7 years ago

Commit is fixing same issue on kombu 4.0.2

emiel commented 6 years ago

Awesome! Thanks.