Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751227AbZIQAHz (ORCPT ); Wed, 16 Sep 2009 20:07:55 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750788AbZIQAHy (ORCPT ); Wed, 16 Sep 2009 20:07:54 -0400 Received: from x35.xmailserver.org ([64.71.152.41]:40554 "EHLO x35.xmailserver.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750727AbZIQAHx (ORCPT ); Wed, 16 Sep 2009 20:07:53 -0400 X-AuthUser: davidel@xmailserver.org Date: Wed, 16 Sep 2009 17:07:56 -0700 (PDT) From: Davide Libenzi X-X-Sender: davide@makko.or.mcafeemobile.com To: Gilad Benjamini cc: Linux Kernel Mailing List Subject: Re: epoll and closed file descriptors In-Reply-To: <023c01ca3724$9f90fcb0$deb2f610$@com> Message-ID: References: <023c01ca3724$9f90fcb0$deb2f610$@com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) X-GPG-FINGRPRINT: CFAE 5BEE FD36 F65E E640 56FE 0974 BF23 270F 474E X-GPG-PUBLIC_KEY: http://www.xmailserver.org/davidel.asc MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1384 Lines: 35 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/