HBPVIS / ZeroEQ

Cross-platform C++ library for fast binary and REST messaging
https://hbpvis.github.io/
Other
41 stars 25 forks source link

http server may hang in receive() when remote connection is closed abruptly #157

Closed rdumusc closed 8 years ago

rdumusc commented 8 years ago

The application deadlocks at ::zmq::send() at lines 195-197 of server.cpp trying to send a return code 200:

if( ::zmq_send( socket, id, idSize, ZMQ_SNDMORE ) != idSize ||
        ::zmq_send( socket, rep.c_str(), rep.length(), more ) !=
        int( rep.length( )))
{
ZEROEQWARN << "Could not send HTTP response header: "
                          << zmq_strerror( zmq_errno( )) << std::endl;
return;
}
tribal-tec commented 8 years ago

Setting ZMQ_LINGER to something low or even 0 is one fix. ZMQ_NOBLOCK could as well, but appears to have issue on closing the socket: http://stackoverflow.com/questions/7538988/zeromq-how-to-prevent-infinite-wait

tribal-tec commented 8 years ago

Thanks to @favreau for testing. ZMQ_NOBLOCK seems to do the trick. Will attack this next week and try to add test for it :)

favreau commented 8 years ago

Thanks @tribal-tec ! :)