py-amqplib connection close failure on Google App Engine only

162 Views Asked by At

I'm trying to use py-amqplib on Google App Engine to communicate with rabbitmq cluster (also host on App Engine). I have everything working as expected except that when I go to close the connection I an exception thrown:

Exception on /api/***** [POST]
    ....
    conn.close()
  File "/base/data/home/apps/s~proj/1.382630193282536254/lib/amqplib/client_0_8/connection.py", line 314, in close
    (10, 61),    # Connection.close_ok
  File "/base/data/home/apps/s~project/1.382630193282536254/lib/amqplib/client_0_8/abstract_channel.py", line 97, in wait
    return self.dispatch_method(method_sig, args, content)
  File "/base/data/home/apps/s~project/1.382630193282536254/lib/amqplib/client_0_8/abstract_channel.py", line 115, in dispatch_method
    return amqp_method(self, args)
  File "/base/data/home/apps/s~project/1.382630193282536254/lib/amqplib/client_0_8/connection.py", line 415, in _close_ok
    self._do_close()
  File "/base/data/home/apps/s~project/1.382630193282536254/lib/amqplib/client_0_8/connection.py", line 160, in _do_close
    self.transport.close()
  File "/base/data/home/apps/s~project/1.382630193282536254/lib/amqplib/client_0_8/transport.py", line 139, in close
    self.sock.shutdown(socket.SHUT_RDWR)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/socket.py", line 222, in meth
    return getattr(self._sock,name)(*args)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 1148, in shutdown
    raise _SystemExceptionFromAppError(e)
error: [Errno 22] Invalid argument

I assume this has to do with app engine's remote_socket implementation which takes over all outbound socket communication.

I've verified that when I run the code locally and through the app engine dev server the connection closes properly (i.e. when its not using remote sockets).

So I'm looking for one of two things:

1) an alternate way to shutdown the amqp connection without throwing a socket error, or confirmation that despite the error, the socket is closed and not left open.

2) An alternate amqp python module that works with app engine. I've tried 'amqp' which is fork of 'amqplib' but it requires ctypes and failed to load on app-engine. I've tried pika which also fails on app engine due to the fnctrl module. Carrot and Kombu both have swappable backend but they seem to either depend on c-libraries or use amqplib as the backend.

0

There are 0 best solutions below