qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Conway <acon...@redhat.com>
Subject Re: Problems with fork and qpid
Date Mon, 17 Jan 2011 15:33:35 GMT
On 01/12/2011 10:48 AM, Niklas Röjemo wrote:
> Hi All,
>
> I have problem with interaction between fork and qpid when using qpid
> from mrg 1.3. The program worked using mrg 1.1. The problem can be
> triggered with a small program that sends a message on qpid and then
> forks a minimal child. The child will terminate with a segmentation fault.
>
> The test program is next, followed by some output from gdb.
>
> ==============
> #include<sys/wait.h>
>
> #include<qpid/client/Connection.h>
> #include<qpid/client/Session.h>
> #include<qpid/client/Message.h>
>
> int main(int argc, char** argv) {
>    const char* key     = "rojemo_ts";
>    const char* exchange = "amq.direct";
>    const char* host    = "qpid-vm";
>    int         port    = 5672;
>
>    for(int i = 0; i<  10; ++i) {
>      {
>        qpid::client::Connection connection;
>        connection.open(host, port);
>        qpid::client::Session session = qpid::client::sync(connection.newSession());
>        qpid::client::Message message;
>        message.getDeliveryProperties().setRoutingKey(key);
>        message.setData("testing");
>        session.messageTransfer(qpid::client::arg::content=message,
> 			      qpid::client::arg::destination=exchange);
>        session.sync();
>        session.close();
>        connection.close();
>      }
>
>      {
>        pid_t pid = fork();
>        if(!pid) {
> 	sleep(1);
> 	exit(0);
>        } else {
> 	int status;
> 	wait(&status);
>        }
>      }
>    }
> }
> ==============
>
> Only one message is sent before the child process dies (also the main
> process terminates).
>
> (gdb) run
> Starting program: /users/rojemo/work/mareeba-1/forkservers/test/x86_64_linux/qpid_test_g
> [Thread debugging using libthread_db enabled]
> [New Thread 0x40a00940 (LWP 18851)]
> Detaching after fork from child process 18852.
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x40a00940 (LWP 18851)]
> 0x000000375ca08ca0 in pthread_mutex_lock () from /lib64/libpthread.so.0
> (gdb) where
> #0  0x000000375ca08ca0 in pthread_mutex_lock () from /lib64/libpthread.so.0
> #1  0x00000034e266b97a in qpid::sys::Mutex::lock() () from /usr/lib64/libqpidclient.so.3
> #2  0x00000034e2b2a377 in qpid::sys::Poller::wait(qpid::sys::Duration) () from /usr/lib64/libqpidcommon.so.3
> #3  0x00000034e2b2adc7 in qpid::sys::Poller::run() () from /usr/lib64/libqpidcommon.so.3
> #4  0x00000034e2b2101a in ?? () from /usr/lib64/libqpidcommon.so.3
> #5  0x000000375ca0673d in start_thread () from /lib64/libpthread.so.0
> #6  0x000000375bed3f6d in clone () from /lib64/libc.so.6
>
> The main process is waiting in the call to wait.
>
>
>    Regards,
>    Niklas
>
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>

The qpid client library creates background threads, so forking a qpid client 
like this won't work. For some info on why forking & pthreads don't coexist well 
see the"Rationale" section of: 
http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_atfork.html

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Mime
View raw message