lkml.org 
[lkml]   [2009]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: epoll and closed file descriptors
On Wed, 16 Sep 2009, Gilad Benjamini wrote:

> I am running repeatedly into a scenario where epoll notifies userland of
> events on a closed file descriptor.
> I am running a single thread application, on a single CPU machine so
> multiple threads isn't the issue.
>
> A sample set of events that I have seen
> - File descriptor (13) for a socket is closed
> - epoll_wait returns with no events.
> - Several epoll related calls happen
> - More than 20 seconds after the "close", epoll_wait finds an event on fd 13
> with EPOLLIN|EPOLLERR|EPOLLHUP.
> - epoll_wait continues to report this event

Epoll removes the fd from its container, when the last instance of the
underlying kernel file pointer is released (or when you explicitly
remove it with epoll_ctl(EPOLL_CTL_DEL)).
If you continue to get the event, it means that someone else has an
instance of the socket (that, looking at the events, saw a shutdown) open,
by hence keeping the kernel object alive.
If you don't want to see the events, just remove the socket from the epoll
set before closing.
Or, you remove the socket the first time you see an EPOLLHUP.



- Davide




\
 
 \ /
  Last update: 2009-09-17 02:11    [W:0.047 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site