Re: epoll and shared fd's



On Jan 25, 2008 12:57 AM, Davide Libenzi <davidel@xxxxxxxxxxxxxxx> wrote:

On Thu, 24 Jan 2008, Pierre Habouzit wrote:

On Fri, Jan 18, 2008 at 09:10:18PM +0000, Davide Libenzi wrote:
On Fri, 18 Jan 2008, Pierre Habouzit wrote:

Hi,

I just came across a strange behavior of epoll that seems to
contradict the documentation. Here is what happens:

* I have two processes P1 and P2, P1 accept()s connections, and send the
resulting file descriptors to P2 through a unix socket.

* P2 registers the received socket in his epollfd.

[time passes]

* P2 is done with the socket and closes it

* P2 gets events for the socket again !


Though the documentation says that if a process closes a file
descriptor, it gets unregistered. And yes I'm sure that P2 doens't dup()
the file descriptor. Though (because of a bug) it was still open in
P1[0], hence the referenced socket still live at the kernel level.

Of course the userland workaround is to force the EPOLL_CTL_DEL before
the close, which I now do, but costs me a syscall where I wanted to
spare one :|

For epoll, a close is when the kernel file* is released (that is, when all
its instances are gone).
We could put a special handling in filp_close(), but I don't think is a
good idea, and we're better live with the current behaviour.

Okay, maybe updating the linux manpages to be more clear about that is
the way to go then. Thanks

Sure. I'll send Michael Kerrisk and updated statement for the A6 answer in
the epoll man page.

Thanks Davide -- yes please send me a patch.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: epoll and shared fds
    ... resulting file descriptors to P2 through a unix socket. ... P2 registers the received socket in his epollfd. ... Though the documentation says that if a process closes a file ... For epoll, a close is when the kernel file* is released (that is, when all ...
    (Linux-Kernel)
  • Re: epoll and shared fds
    ... resulting file descriptors to P2 through a unix socket. ... P2 registers the received socket in his epollfd. ... Though the documentation says that if a process closes a file ... For epoll, a close is when the kernel file* is released (that is, when all ...
    (Linux-Kernel)
  • Re: epoll gives broken results when interrupted with a signal
    ... >> The epoll is being used to monitor only a handful of file descriptors. ... >> by a parent process, and then passed on to the process doing the epoll. ... domain socket between the two processes. ...
    (Linux-Kernel)
  • Re: epoll design problems with common fork/exec patterns
    ... But then, if the epoll documentation has to document the full Unix/Linux files semantic, nobody will read it. ... the last closeso that underlying file refcount is 0 ... epoll has to deal with files, but documentation is a User side documentation, so has to use 'file descriptors'. ...
    (Linux-Kernel)
  • Re: epoll and shared fds
    ... resulting file descriptors to P2 through a unix socket. ... P2 registers the received socket in his epollfd. ... Though the documentation says that if a process closes a file ... For epoll, a close is when the kernel file* is released (that is, when all ...
    (Linux-Kernel)