linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Kernel bug with UNIX sockets not detecting other end gone?
@ 2001-05-17 22:57 Chris Evans
  2001-05-17 22:59 ` Alan Cox
  2001-05-18 17:24 ` Kurt Roeckx
  0 siblings, 2 replies; 8+ messages in thread
From: Chris Evans @ 2001-05-17 22:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: davem


Hi,

I wonder if the following is a bug? It certainly differs from FreeBSD 4.2
behaviour, which gives the behaviour I would expect.

The following program blocks indefinitely on Linux (2.2, 2.4 not tested).
Since the other end is clearly gone, I would expect some sort of error
condition. Indeed, FreeBSD gives ECONNRESET.

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>

int
main(int argc, const char* argv[])
{
  int the_sockets[2];
  int retval;
  char the_char;
  int opt = 1;

  retval = socketpair(PF_UNIX, SOCK_DGRAM, 0, the_sockets);
  if (retval != 0)
  {
    perror("socketpair");
    exit(1);
  }
  close(the_sockets[0]);
  /* Linux (2.2) blocks here; FreeBSD does not */
  retval = read(the_sockets[1], &the_char, sizeof(the_char));
}

Cheers
Chris


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Kernel bug with UNIX sockets not detecting other end gone?
  2001-05-17 22:57 Kernel bug with UNIX sockets not detecting other end gone? Chris Evans
@ 2001-05-17 22:59 ` Alan Cox
  2001-05-17 23:51   ` Chris Evans
  2001-05-18 17:24 ` Kurt Roeckx
  1 sibling, 1 reply; 8+ messages in thread
From: Alan Cox @ 2001-05-17 22:59 UTC (permalink / raw)
  To: Chris Evans; +Cc: linux-kernel, davem

> The following program blocks indefinitely on Linux (2.2, 2.4 not tested).
> Since the other end is clearly gone, I would expect some sort of error
> condition. Indeed, FreeBSD gives ECONNRESET.

Since its a datagram socket Im not convinced thats a justifiable assumption.

Alan


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Kernel bug with UNIX sockets not detecting other end gone?
  2001-05-17 22:59 ` Alan Cox
@ 2001-05-17 23:51   ` Chris Evans
  2001-05-18  0:32     ` David Schwartz
  0 siblings, 1 reply; 8+ messages in thread
From: Chris Evans @ 2001-05-17 23:51 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel, davem


On Thu, 17 May 2001, Alan Cox wrote:

> > The following program blocks indefinitely on Linux (2.2, 2.4 not tested).
> > Since the other end is clearly gone, I would expect some sort of error
> > condition. Indeed, FreeBSD gives ECONNRESET.
>
> Since its a datagram socket Im not convinced thats a justifiable assumption.

Hmm - there's definitely a Linux inconsistency here. With SOCK_DGRAM,
read() is blocking but write() is giving ECONNRESET.

The ECONNRESET makes sense to me (despite this being a datagram socket),
because the sockets are anonymous. Once one end goes away, the other end
is pretty useless.

Cheers
Chris


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Kernel bug with UNIX sockets not detecting other end gone?
  2001-05-17 23:51   ` Chris Evans
@ 2001-05-18  0:32     ` David Schwartz
  2001-05-18  8:32       ` Olaf Titz
  0 siblings, 1 reply; 8+ messages in thread
From: David Schwartz @ 2001-05-18  0:32 UTC (permalink / raw)
  To: Chris Evans; +Cc: linux-kernel


> Hmm - there's definitely a Linux inconsistency here. With SOCK_DGRAM,
> read() is blocking but write() is giving ECONNRESET.
>
> The ECONNRESET makes sense to me (despite this being a datagram socket),
> because the sockets are anonymous. Once one end goes away, the other end
> is pretty useless.
>
> Cheers
> Chris

	One can justify any behavior, since this is a datagram socket but the
kernel does know that it has been 'disconnected'. One can even justify the
inconcsistent behavior -- the write definitely has no place to go (now), but
the read can't be totally sure that there is no possible way anybody could
ever find the other end and write to it.	I think it would, however, be
preferable to have it return ECONNRESET in all cases (read, write, and
'select'/'poll' should hit on read and write).

	DS


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Kernel bug with UNIX sockets not detecting other end gone?
  2001-05-18  0:32     ` David Schwartz
@ 2001-05-18  8:32       ` Olaf Titz
  0 siblings, 0 replies; 8+ messages in thread
From: Olaf Titz @ 2001-05-18  8:32 UTC (permalink / raw)
  To: linux-kernel

> kernel does know that it has been 'disconnected'. One can even justify the
> inconcsistent behavior -- the write definitely has no place to go (now), but
> the read can't be totally sure that there is no possible way anybody could
> ever find the other end and write to it.

For a socket created with socketpair()? I'm pretty sure there is no
way for any program to find any path to it, and if there is, it's a
kernel bug. Such a socket does not have a legitimate name. (And
getsockname() reliably returns garbage, which is another bug IMHO.)

Olaf

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Kernel bug with UNIX sockets not detecting other end gone?
  2001-05-17 22:57 Kernel bug with UNIX sockets not detecting other end gone? Chris Evans
  2001-05-17 22:59 ` Alan Cox
@ 2001-05-18 17:24 ` Kurt Roeckx
  2001-05-18 20:02   ` Alan Cox
  1 sibling, 1 reply; 8+ messages in thread
From: Kurt Roeckx @ 2001-05-18 17:24 UTC (permalink / raw)
  To: Chris Evans; +Cc: linux-kernel, davem

On Thu, May 17, 2001 at 11:57:45PM +0100, Chris Evans wrote:
> 
> Hi,
> 
> I wonder if the following is a bug? It certainly differs from FreeBSD 4.2
> behaviour, which gives the behaviour I would expect.
> 
> The following program blocks indefinitely on Linux (2.2, 2.4 not tested).
> Since the other end is clearly gone, I would expect some sort of error
> condition. Indeed, FreeBSD gives ECONNRESET.

I'm having a simular problem, but somehow can't recreate it.

The difference is that I set the sockets to non-blocking, and
expect it to return some error.

read() returns 0, with errno set to 0, if the socket is still
open it returns -1 with errno set 11 (EAGAIN).  I can understand
those behaviours.

What I'm seeing however in an other program is that select says I
can read from the socket, and that read returns 0, with errno set
to EGAIN.  I call select() again, with returns and says I can read
from that socket ..., which keeps going on.  It stops from the
moment there is any i/o on an other socket.

Is there any way you can detect the other side is gone without
using write()?  write() shoud return an EPIPE.  Should I be able
to detect it with read(), or some oter system call?


Kurt


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Kernel bug with UNIX sockets not detecting other end gone?
  2001-05-18 17:24 ` Kurt Roeckx
@ 2001-05-18 20:02   ` Alan Cox
  2001-05-18 20:52     ` Kurt Roeckx
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Cox @ 2001-05-18 20:02 UTC (permalink / raw)
  To: Kurt Roeckx; +Cc: Chris Evans, linux-kernel, davem

> What I'm seeing however in an other program is that select says I
> can read from the socket, and that read returns 0, with errno set
> to EGAIN.  I call select() again, with returns and says I can read

No no no. If the read does not return -1 it does not change errno. EOF isnt
an error.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Kernel bug with UNIX sockets not detecting other end gone?
  2001-05-18 20:02   ` Alan Cox
@ 2001-05-18 20:52     ` Kurt Roeckx
  0 siblings, 0 replies; 8+ messages in thread
From: Kurt Roeckx @ 2001-05-18 20:52 UTC (permalink / raw)
  To: Alan Cox; +Cc: Chris Evans, linux-kernel, davem

On Fri, May 18, 2001 at 09:02:51PM +0100, Alan Cox wrote:
> > What I'm seeing however in an other program is that select says I
> > can read from the socket, and that read returns 0, with errno set
> > to EGAIN.  I call select() again, with returns and says I can read
> 
> No no no. If the read does not return -1 it does not change errno. EOF isnt
> an error.

Of course, how stupid of me.


Kurt


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-05-18 20:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-17 22:57 Kernel bug with UNIX sockets not detecting other end gone? Chris Evans
2001-05-17 22:59 ` Alan Cox
2001-05-17 23:51   ` Chris Evans
2001-05-18  0:32     ` David Schwartz
2001-05-18  8:32       ` Olaf Titz
2001-05-18 17:24 ` Kurt Roeckx
2001-05-18 20:02   ` Alan Cox
2001-05-18 20:52     ` Kurt Roeckx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).