[rabbitmq-discuss] RabbitMQ-C: amqp_simple_rpc blocks waiting for frames already received

David Wragg david at rabbitmq.com
Tue Jul 26 16:13:12 BST 2011


Hi Clint,

Clint Miller <clint at rtcreativegroup.com> writes:
> OK, here's the basic example. It shows how the basic.consume method of
> the C++ library is not functioning correctly, but the basic.get works
> correctly.
>
> There's a basic Makefile that will probably require a little tweaking to get it working. It also depends on the 2 following libraries:
>
> - RabbitMQ-C (from the official repository, I built it at rev/changeset ef4df46cc0db)
> - AMQPcpp (from https://github.com/akalend/amqpcpp.git I built it at
> rev/changeset 80b17375f5bed6965acc07477499285b6851c92f)

Thanks, I got it building quite easily.  I'm not sure if I'm able to
reproduce the problem that you described in your original mail, but I
can confirm that it doesn't work for me.

This isn't primarily due to the use of librabbitmq in amqpcpp.  That
looks basically sound (there are some calls to amqp_release_buffers in
AMQPQueue.cpp that should be amqp_maybe_release_buffers, but otherwise I
haven't found anything specifically wrong).

But when I run the program, it aborts.  Running it inside gdb, I get
double free errors reported.  So I ran it under valgrind.  And valgrind
finds many problems in amqpcpp.  (In fairness, it also complains about
some things in librabbitmq, but they are about the use of uninitialized
data, and may be harmless.)

The critical issue is a double free of the message buffer in
AMQPQueue::sendConsumeCommand: At AMQPQueue.cpp#L512, buf is handed to
the AMQPMessage object, and then freed.  But AMQPMessage holds on to
this pointer, and frees it again in its destructor (called via the
message auto_ptr).

valgrind also revealed a lot of cases of amqpcpp trying to use freed
data (e.g. by passing a char* to AMQPQueue::setConsumerTag, you invoke
the implicit conversion to string, and the string data is freed after
the call; but setConsumerTag then uses c_str to get a pointer to the
string data, which is saved in consumer_tag and only used later in
sendConsumeCommand).

I think amqpcpp needs cleaning up with valgrind in order to work
reliably.

David

-- 
David Wragg
Staff Engineer, RabbitMQ
VMware, Inc.


More information about the rabbitmq-discuss mailing list