lib/yahns/acceptor.rb in yahns-0.0.0 vs lib/yahns/acceptor.rb in yahns-0.0.1
- old
+ new
@@ -1,11 +1,11 @@
# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> et. al.
# License: GPLv3 or later (see COPYING for details)
module Yahns::Acceptor # :nodoc:
def spawn_acceptor(logger, client_class, queue)
- accept_flags = Kgio::SOCK_NONBLOCK | Kgio::SOCK_CLOEXEC
Thread.new do
+ accept_flags = Kgio::SOCK_NONBLOCK | Kgio::SOCK_CLOEXEC
Thread.current.abort_on_exception = true
qev_flags = client_class.superclass::QEV_FLAGS
begin
# We want the accept/accept4 syscall to be _blocking_
# so it can distribute work evenly between processes
@@ -19,10 +19,12 @@
rescue Errno::EMFILE, Errno::ENFILE => e
logger.error("#{e.message}, consider raising open file limits")
queue.fdmap.desperate_expire_for(self, 5)
sleep 1 # let other threads do some work
rescue => e
- Yahns::Log.exception(logger, "accept loop error", e) unless closed?
- end until closed?
+ # sleep since this check is racy (and uncommon)
+ break if closed? || (sleep(0.01) && closed?)
+ Yahns::Log.exception(logger, "accept loop", e)
+ end while true
end
end
end