[zeromq-dev] [bug+workaround] socket_t not closed properly, still used

Thijs Terlouw thijsterlouw at gmail.com
Fri Jan 21 15:46:24 CET 2011


On Fri, Jan 21, 2011 at 9:43 PM, Martin Sustrik <sustrik at 250bpm.com> wrote:

> Right. The application thread has to finish the handshake with the I/O
> thread to be able to destroy the socket. Currently the handshake is finished
> using dezombify() function that is called on zmq_socket() or zmq_close().
> Calling dezombify() from common functions like zmq_send() or zmq_recv()
> would mitigate the problem, however, the problem is that the dezombification
> is expensive and would slow down the critical path (actual message passing)
> considerably.

I think there is indeed no need to call it in the critical path, that
should remain as fast as possible. Calling it from zmq_send/zmq_recv
feels like an ugly hack :)

> A possible solution proposed by Martin Lucina was to create a dedicated
> "reaper thread" that would asynchronously dezombify the closed sockets.

That could help indeed, it would make sure the old destroyed socket
stays around shorter and there is no dependency on the other context
functions. With a condition variable it should be relatively easy to
implement, but there would still be a short period the zombies
participate?

> Yes. We can possibly close the socket immediately on first step of the
> finalisation handshake (either term command or when delimiter is received
> depending on ZMQ_LINGER setting) instead of waiting for the whole
> finalisation process to finish.

Yes, when ZMQ_LINGER=0, it should be acceptable to immediately close.
For my scenarios I even don't mind losing a few messages (XREQ/XREP)
when I close a socket, as long as it's just temporary and resolves
quickly.

I still don't totally understand totally though why the closed socket
still participates:
Socket_A <----> Socket_B   (for example XREP --- XREQ)
A does zmq_close(), do you mean B still can send to A for a while
(untill it's fully destructed) and those messages will never reach the
application-layer anymore? I forgot from the debugging when the
tcp-wrapper object was exactly destructed.


Thijs



More information about the zeromq-dev mailing list