benjamin-hodgson / asynqp

An AMQP library for asyncio
MIT License
84 stars 29 forks source link

Synchroniser.notify hits 'unexpected method notification' in tests. #94

Open alexjc opened 7 years ago

alexjc commented 7 years ago

This is hard to reproduce, but in automated tests with two browsers connected we hit this problem reliably:

            try:
                fut = self._futures[method].popleft()
            except IndexError:
                # XXX: we can't just ignore this.
                log.error("Got an unexpected method notification %s", method)
                return

The server is RabbitMQ but this looks like a race condition in asynqp itself. Before we start debugging, any ideas what could be the cause? Thanks!

alexjc commented 7 years ago

I traced this down to Synchronizer class that likely should throw a more specific error when something is attempted that doesn't work with this implementation:

     def await(self, *expected_methods):
         fut = asyncio.Future(loop=self._loop)

         if self.connection_exc is not None:
             fut.set_exception(self.connection_exc)
             return fut

         for method in expected_methods:
+            assert method not in self._futures, "Awaiting multiple %s messages not supported" % method
             self._futures[method].append(fut)
         return fut

How are Channels supposed to be used in asynqp? One per queue? If I want to consume as well as send do I need a separate Channel?