It actually looks like a bug in pika to me. Here's the connection.connect() code that's ultimately raising the exception:
def connect(self):
"""Invoke if trying to reconnect to a RabbitMQ server. Constructing the
Connection object should connect on its own.
"""
self._set_connection_state(self.CONNECTION_INIT)
if self._adapter_connect():
return self._on_connected()
self.remaining_connection_attempts -= 1
LOGGER.warning('Could not connect, %i attempts left',
self.remaining_connection_attempts)
if self.remaining_connection_attempts:
LOGGER.info('Retrying in %i seconds', self.params.retry_delay)
self.add_timeout(self.params.retry_delay, self.connect)
else:
self.callbacks.process(0, self.ON_CONNECTION_ERROR, self, self)
self.remaining_connection_attempts = self.params.connection_attempts
self._set_connection_state(self.CONNECTION_CLOSED)
So, self._adapter_connect()
is clearly not returning True, which suggests the connection is failing. Here's the AsyncoreConnection._adapter_connect
code:
def _adapter_connect(self):
"""Connect to our RabbitMQ broker using AsyncoreDispatcher, then setting
Pika's suggested buffer size for socket reading and writing. We pass
the handle to self so that the AsyncoreDispatcher object can call back
into our various state methods.
"""
if super(AsyncoreConnection, self)._adapter_connect():
self.socket = PikaDispatcher(self.socket, None, self._handle_events)
self.ioloop = self.socket
self._on_connected()
It doesn't return anything! So that if statement in connect
is never going to be True. If I change the method to reflect the pattern all the other adapters use:
def _adapter_connect(self):
"""Connect to our RabbitMQ broker using AsyncoreDispatcher, then setting
Pika's suggested buffer size for socket reading and writing. We pass
the handle to self so that the AsyncoreDispatcher object can call back
into our various state methods.
"""
if super(AsyncoreConnection, self)._adapter_connect():
self.socket = PikaDispatcher(self.socket, None, self._handle_events)
self.ioloop = self.socket
return True
return False
It works fine. I would definitely file that bug!
Edit:
The bug appears to be fixed in the latest version (from github):
def _adapter_connect(self):
"""Connect to our RabbitMQ broker using AsyncoreDispatcher, then setting Pika's suggested buffer size for socket reading and writing. We pass the handle to self so that the AsyncoreDispatcher object can call back into our various state methods.
"""
error = super(AsyncoreConnection, self)._adapter_connect()
if not error:
self.socket = PikaDispatcher(self.socket, None,
self._handle_events)
self.ioloop = self.socket
self._on_connected()
return error