zeromq/libzmq — pull request #1019 by willstrang (2014-05-09 14:44:58+00:00)
Title: Issue #1017: add ZMQ_HANDSHAKE_IVL time limit on connection handshake

In our use of zeromq, we have had other software connect to a listening TCP socket, and then just sit there with the socket open. If the connecting end sends enough bytes, that will initiate handshaking, which will either succeed, or fail and disconnect. But if it sends nothing, or too few bytes for handshaking to reach a conclusion, the socket just sits there open. Such "hanging" connections can interfere with desired connections, or could even be used as an attack. My solution is to add a timer in stream_engine to limit the time from connect to the end of handshaking, and to disconnect on timeout. This also works with zeromq sockets that are connecting, if the accepting end does not start handshaking. I made this time limit configurable by zmq_setsockopt as ZMQ_HANDSHAKE_IVL, defaulted to 30 seconds.