[zeromq-dev] segfault in zmq_connect

Ian Barber ian.barber at gmail.com
Wed Dec 8 15:00:13 CET 2010


Interesting thing I just noticed - the same thing is not true of child
processes. E.g.

init
fork
-> init

goes wrong, but

fork
-> init
-> fork
----> init

doesn't!

Ian

On Wed, Dec 8, 2010 at 11:52 AM, Ian Barber <ian.barber at gmail.com> wrote:

> I have had a similar issue (using the PHP bindings, but it looks like it).
>
> If I move the context creation below the fork, it works fine, even though I
> create a new context in the fork. Moving just the bind or the bind + socket
> creation don't change it.
>
> <?php
> function client_thread() {
> echo "Starting Client!\n";
> $context = new ZMQContext();
>  $client = new ZMQSocket($context, ZMQ::SOCKET_REQ);
> $client->connect("ipc://frontend.ipc");
>  echo "Ready!\n";
>  $client->send("Hi");
>  echo "Exiting";
> exit();
> }
>
> $context = new ZMQContext();
>  $frontend = new ZMQSocket($context, ZMQ::SOCKET_XREP);
> $frontend->bind("ipc://frontend.ipc");
>  echo "Forking \n";
> $pid = pcntl_fork();
>  if($pid == 0) {
> client_thread();
> return;
>  }
>  echo "Receiving \n";
>  echo $frontend->recv();
>
> On Wed, Dec 8, 2010 at 11:41 AM, Mahadevan R <mdevan.r at gmail.com> wrote:
>
>> Hi Samuel,
>>
>> On Wed, Dec 8, 2010 at 4:48 PM, Samuel Tardieu <sam at rfc1149.net> wrote:
>>
>>>
>>>
>>> 2010/12/8 Mahadevan R <mdevan.r at gmail.com>
>>>
>>>
>>>> I'm getting a strange segfault with the following stack:
>>>>
>>>> #0  0x00007f623e64edd0 in _int_malloc () from /lib/libc.so.6
>>>> #1  0x00007f623e650ad8 in malloc () from /lib/libc.so.6
>>>> #2  0x00007f623c375d4f in zmq::create_pipe (reader_parent_=0x13bdde0,
>>>> writer_parent_=0x13c0e10, hwm_=1000,
>>>>     swap_size_=0, reader_=0x7fff08b49ad8, writer_=0x7fff08b49ad0) at
>>>> yqueue.hpp:52
>>>> #3  0x00007f623c37c347 in zmq::socket_base_t::connect (this=0x13bdde0,
>>>>     addr_=0x7f623c594621 "tcp://127.0.0.1:9988") at socket_base.cpp:406
>>>>
>>>> This is on a 64-bit debian lenny, fairly easily reproducible. Zeromq
>>>> version is 2.1.0 beta. The crash occurs in a forked child, although parent's
>>>> context is not touched (not sure if this is relevant). There are many
>>>> children, all connecting to the same ZMQ_REQ. Context is inited with thread
>>>> pool size of 1. There is a single ZMQ_REP process (thread pool size 1).
>>>>
>>>> Any hints?
>>>>
>>>
>>> Have you by chance called bind() in the parent process before calling
>>> fork()?
>>>
>>
>> Nope. The child calls only zmq_connect(), and before segfaulting it had
>> managed to connect successfully before. The pattern is like
>> connect/send-request/recv-reply/close.
>>
>> Cheers,
>> -Mahadevan.
>>
>>
>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20101208/5e48214b/attachment.htm>


More information about the zeromq-dev mailing list