From: Eric Wong Date: Wed, 8 May 2019 19:04:17 +0000 (+0000) Subject: DS: epoll: fix misordered EPOLL_CTL_DEL call X-Git-Tag: v1.2.0~296^2 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=90c5a78c8f6239b27c32b816d1cd029196ba2fe2 DS: epoll: fix misordered EPOLL_CTL_DEL call Any operations on an fd after POSIX::close() are invalid, so epoll_ctl will fail. Worse off, in a multi-threaded Perl, the fd may be reused by another thread and EPOLL_CTL_DEL can hit the wrong file description as a result. cf. https://rt.cpan.org/Ticket/Display.html?id=129487 --- diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index c03bd5dd..779215c9 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -333,8 +333,8 @@ sub EpollEventLoop { } else { my $fd = $ev->[0]; warn "epoll() returned fd $fd w/ state $state for which we have no mapping. removing.\n"; - POSIX::close($fd); epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, 0); + POSIX::close($fd); } next; }