[zeromq-dev] Bug/Crash: ZMQ + fork()

Christian Heimes lists at cheimes.de
Thu Jun 21 16:22:56 CEST 2012


Hi all!

This is a follow to my last posting. I did some further testing and came
to the conclusion that ZMQ doesn't mix with fork(). This may sound bad
but it's actually not. It's just something that should be mentioned in
the docs, perhaps in large, friendly letters. :)

I've attached a modified hello world client that shows the issue. It
uses fork() after the initial connect() but before the first send(). The
standard hwserver.py only receives messages from the parent process:


Parent
======
Received request:  Hello parent
...


Client case 1
=============

The client usually outputs this. Note how the child process tries to
send one message but gives up with EAGAIN.

$ python hwclient_fork.py
Connecting to hello world server...
Running parent
Sending request  1 parent ...
Running child
Sending request  1 child ...
Received reply  1 parent [ World ]
Sending request  2 parent ...
Resource temporarily unavailable (signaler.cpp:201)
Received reply  2 parent [ World ]
Sending request  3 parent ...
Received reply  3 parent [ World ]
Sending request  4 parent ...
Received reply  4 parent [ World ]
Sending request  5 parent ...
Received reply  5 parent [ World ]
Sending request  6 parent ...
Received reply  6 parent [ World ]
Sending request  7 parent ...
Received reply  7 parent [ World ]
Sending request  8 parent ...
Received reply  8 parent [ World ]
Sending request  9 parent ...
Received reply  9 parent [ World ]


Client case 2
=============

On approx. one out of five times the client processes lock up and block
indefinitely. A manual keyboard interrupt causes a segfault:

$ python hwclient_fork.py
Connecting to hello world server...
Running parent
Sending request  1 parent ...
Running child
Sending request  1 child ...
^CTraceback (most recent call last):
  File "hwclient_fork.py", line 22, in <module>
    message = socket.recv()
  File "socket.pyx", line 616, in zmq.core.socket.Socket.recv
(zmq/core/socket.c:5961)
  File "socket.pyx", line 650, in zmq.core.socket.Socket.recv
(zmq/core/socket.c:5832)
Traceback (most recent call last):
  File "socket.pyx", line 119, in zmq.core.socket._recv_copy
(zmq/core/socket.c:1664)
  File "hwclient_fork.py", line 22, in <module>
    message = socket.recv()
  File "error.pyx", line 92, in zmq.core.error.ZMQError.__init__
(zmq/core/error.c:936)
  File "socket.pyx", line 616, in zmq.core.socket.Socket.recv
(zmq/core/socket.c:5961)
  File "socket.pyx", line 650, in zmq.core.socket.Socket.recv
(zmq/core/socket.c:5832)
KeyboardInterrupt
  File "socket.pyx", line 119, in zmq.core.socket._recv_copy
(zmq/core/socket.c:1664)
  File "error.pyx", line 92, in zmq.core.error.ZMQError.__init__
(zmq/core/error.c:936)
KeyboardInterrupt
Assertion failed: ok (mailbox.cpp:84)
Abgebrochen (Speicherabzug geschrieben)

(That's German for segmentation fault)

HTH,
Christian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hwclient_fork.py
Type: text/x-python
Size: 557 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120621/820ebec3/attachment.py>


More information about the zeromq-dev mailing list