eandersson / amqpstorm

Thread-safe Python RabbitMQ Client & Management library
MIT License
188 stars 36 forks source link

Connection timeout to cloudamqp.com #52

Closed gastlich closed 6 years ago

gastlich commented 6 years ago

Hi there, thanks for a great package and implementing heartbeat timer.

I was developing something locally (pointing to local rabbitmq) and it was working perfectly, but after deploying my app to the cloud and pointing to cloudamqp.com, your package cannot connect anymore...

I've tried to compare your package with other clients:

Python 3.6.3 (default, Oct  3 2017, 21:45:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> RABBIT_DSN = os.getenv('RABBIT_DSN')
>>> import pika
>>> connection = pika.BlockingConnection(pika.URLParameters(RABBIT_DSN))
>>> channel = connection.channel() # worked
>>> import rabbitpy
>>> connection = rabbitpy.Connection(RABBIT_DSN)
>>> channel = connection.channel() # worked
>>> import amqpstorm
>>> connection = amqpstorm.UriConnection(RABBIT_DSN) # timeout :(
command terminated with exit code 137

the last command terminates the terminal.

Traceback (most recent call last):
  File "importer.py", line 240, in <module>
    connection = UriConnection(RABBIT_DSN)
  File "/app/.local/share/virtualenvs/src-sjxfABcx/lib/python3.6/site-packages/amqpstorm/uri_connection.py", line 46, in __init__
    **kwargs)
  File "/app/.local/share/virtualenvs/src-sjxfABcx/lib/python3.6/site-packages/amqpstorm/connection.py", line 70, in __init__
    self.open()
  File "/app/.local/share/virtualenvs/src-sjxfABcx/lib/python3.6/site-packages/amqpstorm/connection.py", line 193, in open
    self._wait_for_connection_state(state=Stateful.OPEN)
  File "/app/.local/share/virtualenvs/src-sjxfABcx/lib/python3.6/site-packages/amqpstorm/connection.py", line 315, in _wait_for_connection_state
    raise AMQPConnectionError('Connection timed out')
amqpstorm.exception.AMQPConnectionError: Connection timed out

For you information, our deployment is made to kubernetes on GCP. The connection URL string has a following format: amqp://user:password@something.something.cloudamqp.com/user

I would appreciate any help :)

eandersson commented 6 years ago

I'll try to take a look tonight. I have used cloudamqp in the past for testing.

eandersson commented 6 years ago

The issue seems to be that cloudamqp limits the max frame size to 16384 and when amqpstorm tries to forcefully negotiate the max allowed frame size 131072 it silently fails.

I'll implement some logic to better negotiate these things when connecting.

As a temporarily work-around you can change this line to forcefully lower the max frame buffer used by amqpstorm to 16384 and it should work. https://github.com/eandersson/amqpstorm/blob/master/amqpstorm/base.py#L11

gastlich commented 6 years ago

@eandersson thank you @eandersson for your help, I will try your suggestion tomorrow

eandersson commented 6 years ago

The above pull request should fix any issues with cloudamqp.com. I haven't uploaded it to pypi yet, so you will need to pull it down manually if you want to test it out, but I'll probably ship it in a day or two.

eandersson commented 6 years ago

Version 2.4.1 with the patch is now live. Let me know if you have any issues.

gastlich commented 6 years ago

@eandersson thanks for the quick release and fixing the issue :) it looks like it's working

eandersson commented 6 years ago

@gastlich glad to hear it worked! Let me know if you find any more bugs etc!