[nanomsg] nn_close() of nanomsg socket hangs forever

  • From: "Jason E. Aten" <j.e.aten@xxxxxxxxx>
  • To: nanomsg <nanomsg@xxxxxxxxxxxxx>
  • Date: Sat, 31 Jan 2015 18:38:29 -0800

In my application, this doesn't happen for a while, but then after a while,
the server doing an nn_close() on a nanomsg socket hangs forever.

I read in close 2 man page:

       When  dealing with sockets, you have to be sure that there is no
*recv*(2) still blocking on it on

       another thread, otherwise it might block forever, since no more
messages will be  sent  via  the

       socket.  Be  sure  to  use  *shutdown*(2) to shut down all parts the
connection before closing the

       socket.


Moreover I see this example discussion [the answer by Joseph Quinsey
<http://stackoverflow.com/users/318716/joseph-quinsey>] of how to properly
close a socket:

http://stackoverflow.com/questions/12730477/close-is-not-closing-socket-properly

Mr. Quinsey suggests that there are three (3) steps needed to successfully
close without hanging:

a) getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &len)); // to clear
any error on the socket

b) shutdown(fd, SHUT_RDWR); // to terminate reliable delivery

c) close(fd); // finally


I don't see nanomsg doing a) or b), so I tend to think this is a bug in the
nn_close() implimentation, and these two steps should be added.

Thoughts?


Thanks!

- Jason

Other related posts: