benjamin-hodgson / asynqp

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

AMQP protocol error while valid usage #37

Closed socketpair closed 9 years ago

socketpair commented 9 years ago

I spent over two hours to detect that (!). Example:

#!/usr/bin/env python3

import asyncio
import asynqp

@asyncio.coroutine
def bug():
    connection = yield from asynqp.connect()
    yield from asyncio.wait([connection.open_channel(), connection.open_channel()])

loop = asyncio.get_event_loop()
loop.run_until_complete(bug())

Will generate this logs in rabbitmq:

=INFO REPORT==== 16-Sep-2015::01:44:31 ===
accepting AMQP connection <0.2940.0> (127.0.0.1:54980 -> 127.0.0.1:5672)

=ERROR REPORT==== 16-Sep-2015::01:44:31 ===
Error on AMQP connection <0.2940.0> (127.0.0.1:54980 -> 127.0.0.1:5672, vhost: '/', user: 'guest', state: running), channel 1:
{amqp_error,command_invalid,"second 'channel.open' seen",'channel.open'}

=INFO REPORT==== 16-Sep-2015::01:44:31 ===
closing AMQP connection <0.2940.0> (127.0.0.1:54980 -> 127.0.0.1:5672)
socketpair commented 9 years ago

So, general question, is your library allows asyncio parallel task execution? for example, sending messages in parallel creating exchanges and so on?

socketpair commented 9 years ago

I have also discovered that version available in pip is old. https://github.com/benjamin-hodgson/asynqp/commit/9254ae6f7d440f5783385792f7efd4b2a412c648#commitcomment-13247539

socketpair commented 9 years ago

I have checked, same bug reproduces on master branch.

Your sources are complicated for me, but seems same problem described here:

http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2013-March/025928.html

benjamin-hodgson commented 9 years ago

Thanks for the bug report. I think this line needs to be moved up above the try/except. I'll fix that now.

The version of asynqp available on the Cheese Shop is version 0.4, which was tagged at the end of June. 0.4 is the latest release; development continues on the master branch. If you want to use the development version, you have to clone this repo and install it manually.

socketpair commented 9 years ago

Thanks! Very fast! I already found bug and starts to create PR, but you was faster :)

What about https://github.com/benjamin-hodgson/asynqp/issues/37#issuecomment-140535172 ?

benjamin-hodgson commented 9 years ago

Should work out of the box, as long as you aren't using more than one thread (which isn't a good idea with asyncio anyway). Any issues with cooperative concurrency when using asynqp should be reported as a bug :smile:

socketpair commented 9 years ago

OK. Will report if found!