Skip to content

Commit aea11bc

Browse files
author
Amichai Schreiber
committed
in recv, make sure all frames are read from the same channel. seems to fix #97
1 parent 9110060 commit aea11bc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Modules/_librabbitmq/connection.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ PyRabbitMQ_recv(PyRabbitMQ_Connection *self, PyObject *p,
13021302
amqp_connection_state_t conn, int piggyback)
13031303
{
13041304
amqp_frame_t frame;
1305+
amqp_channel_t cur_channel = 0;
13051306
amqp_basic_deliver_t *deliver;
13061307
amqp_basic_properties_t *props;
13071308
PY_SIZE_TYPE body_target;
@@ -1330,6 +1331,8 @@ PyRabbitMQ_recv(PyRabbitMQ_Connection *self, PyObject *p,
13301331
if (frame.frame_type != AMQP_FRAME_METHOD) continue;
13311332
if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) goto altframe;
13321333

1334+
cur_channel = frame.channel;
1335+
13331336
delivery_info = PyDict_New();
13341337
deliver = (amqp_basic_deliver_t *)frame.payload.method.decoded;
13351338
/* need consumer tag for later.
@@ -1348,7 +1351,9 @@ PyRabbitMQ_recv(PyRabbitMQ_Connection *self, PyObject *p,
13481351
}
13491352

13501353
Py_BEGIN_ALLOW_THREADS;
1351-
retval = amqp_simple_wait_frame(conn, &frame);
1354+
retval = cur_channel == 0 ?
1355+
amqp_simple_wait_frame(conn, &frame) :
1356+
amqp_simple_wait_frame_on_channel(conn, cur_channel, &frame);
13521357
Py_END_ALLOW_THREADS;
13531358
if (retval < 0) break;
13541359

@@ -1358,6 +1363,9 @@ PyRabbitMQ_recv(PyRabbitMQ_Connection *self, PyObject *p,
13581363
goto finally;
13591364
}
13601365

1366+
/* if piggybacked, 'channel' is still 0 at this point */
1367+
cur_channel = frame.channel;
1368+
13611369
/* channel */
13621370
channel = PyInt_FromLong((unsigned long)frame.channel);
13631371

@@ -1371,7 +1379,7 @@ PyRabbitMQ_recv(PyRabbitMQ_Connection *self, PyObject *p,
13711379

13721380
for (i = 0; body_received < body_target; i++) {
13731381
Py_BEGIN_ALLOW_THREADS;
1374-
retval = amqp_simple_wait_frame(conn, &frame);
1382+
retval = amqp_simple_wait_frame_on_channel(conn, cur_channel, &frame);
13751383
Py_END_ALLOW_THREADS;
13761384
if (retval < 0) break;
13771385

0 commit comments

Comments
 (0)