[zeromq-dev] Problem with ZMQ_LINGER

Soren Hansen soren at linux2go.dk
Wed Jul 29 13:58:27 CEST 2015

I have a problem with ZMQ_LINGER not behaving as documented.


If you compile and run that application with a small value like 1000
as its argument, everything is fine. The sender sends the message and
the receiver receives it and both terminate.

However, if the message size is quite large (I use 50000000 to
reproduce it locally), the sender will say that it has sent the
message and terminate, but the receiver will sit there forever,
waiting for a message.

I've tested it against Zmq 4.0.4 as well as master.

We first noticed this problem across our LAN where it was much easier
to reproduce. Any message that exceeded 2*net.core.wmem_max would not
make it to the receiver. It appears that the connection is terminated
immediately when the sender calls zmq_close(), regardless of the fact
that the message has yet to be fully sent. Presumably, single messages
usually fit in the tcp buffer, so a single sendto() syscall will fill
suffice, but if multiple sendto() calls are needed, the connection
might be terminated in the mean time.

ZMQ_LINGER = -1 as well as ZMQ_LINGER = 5000 both yielded same result.
I imagine something in the linger logic fails to take this case into
account, but I've not been able to find the culprit.

There's already https://zeromq.jira.com/browse/LIBZMQ-551 and
https://zeromq.jira.com/browse/LIBZMQ-554 filed about the issue and
there was a mailing list discussion back in 2013 about it:


...but no solution has appeared.

I think this is a critical issue. The documentation promises that
these messages will be delivered, but the reality is different. For
now, we've resorted to boosting the size of the buffers, but it's only
a matter of time before someone decides to send even bigger messages
and then we have the same problem which was very hard to track down to
begin with.

What can I do to help solve this issue?

Soren Hansen

More information about the zeromq-dev mailing list