[nanomsg] Re: [PATCH] Terminate astream if initializing usock failed

  • From: Nir Soffer <nirsof@xxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Tue, 12 Mar 2013 11:59:18 +0200

On Tue, Mar 12, 2013 at 11:01 AM, Martin Sustrik <sustrik@xxxxxxxxxx> wrote:

> Hi Nir,
>
> What was the error you were getting from setsockopt(). If it was EBADF or
> ENOTSOCK, the patch is solving a symptom rather than the cause.
>
> The scenario would look like this:
>
> 1. Socket is terminated by the peer.
> 2. Local socket is closed by nanomsg.
> 3. Nanomsg still tries to tune the closed socket.
> 4. setsockopt() returns EBADF.
>

On OS X the scenario is this:

1. client connects and close the socket
2. server accept a new socket
3. server tune the socket
4. setsockopt fail with EINVAL (looks like a bug in OS X, as the value is
valid (e.g. 128K receive buffer)

Old code assert here and die

New code return -EINVAL

nn_assert_init terminates and the server continues.


>
> I am not 100% convinced that's the case, however, even after applying the
> patch, the ipc_shutdown test fails on my boxwith one of the following
> errors:
>
> Socket operation on non-socket [88] (/home/sustrik/nanomsg/src/**
> utils/aio_posix.inc:894)
> Bad file descriptor [9] (/home/sustrik/nanomsg/src/**
> utils/aio_posix.inc:894)
>

On Linux the scenario looks like this:

1. client connects and close the socket
2. server accept a new socket
3. server tune the socket and succeeds
4. server invokes nn_stream_init
5 nn_usock_recv_raw fails with EBADF

If you add EBADF to the other expected errors, nn_usock_recv fail when it
assert that (*self->sink)->err is not NULL?!

See https://github.com/250bpm/nanomsg/issues/21#issuecomment-14713897

So this patch does fix the error on OS X, but not the other error on Linux.

Do you have an idea why the err function pointer is NULL?

Other related posts: