From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DAA2520078 for ; Tue, 7 Jun 2016 07:39:10 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH 2/5] queue_*: check for closed IO objects Date: Tue, 7 Jun 2016 07:39:05 +0000 Message-Id: <20160607073908.31035-3-e@80x24.org> In-Reply-To: <20160607073908.31035-1-e@80x24.org> References: <20160607073908.31035-1-e@80x24.org> List-Id: Using a high max_events may mean some IO objects are closed after they're retrieved from the kernel but before our Ruby process has had a chance to get to them. --- lib/yahns/queue_epoll.rb | 1 + lib/yahns/queue_kqueue.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/yahns/queue_epoll.rb b/lib/yahns/queue_epoll.rb index 6d8a6ca..7f5c038 100644 --- a/lib/yahns/queue_epoll.rb +++ b/lib/yahns/queue_epoll.rb @@ -44,6 +44,7 @@ def worker_thread(logger, max_events) thr_init begin epoll_wait(max_events) do |_, io| # don't care for flags for now + next if io.closed? # Note: we absolutely must not do anything with io after # we've called epoll_ctl on it, io is exclusive to this diff --git a/lib/yahns/queue_kqueue.rb b/lib/yahns/queue_kqueue.rb index 531912b..229475c 100644 --- a/lib/yahns/queue_kqueue.rb +++ b/lib/yahns/queue_kqueue.rb @@ -53,6 +53,7 @@ def worker_thread(logger, max_events) thr_init begin kevent(nil, max_events) do |_,_,_,_,_,io| # don't care for flags for now + next if io.closed? # Note: we absolutely must not do anything with io after # we've called kevent(...,EV_ADD) on it, io is exclusive to this # thread only until kevent(...,EV_ADD) is called on it.