From 5cf2c7d9543a9f25efb69e4693255c52678b0571 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 10 Oct 2009 12:14:25 -0700 Subject: thread_spawn: more robust loop Bad stuff happens, even in our own code because sometimes we don't know what we're doing. So log it so we'll know to fix it and let life go on... --- lib/rainbows/thread_spawn.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/rainbows') diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb index 35a575e..cafdd33 100644 --- a/lib/rainbows/thread_spawn.rb +++ b/lib/rainbows/thread_spawn.rb @@ -26,14 +26,14 @@ module Rainbows [:TERM, :INT].each { |sig| trap(sig) { exit(0) } } # instant shutdown logger.info "worker=#{worker.nr} ready with ThreadSpawn" - while alive && master_pid == Process.ppid + begin ret = begin alive.chmod(m = 0 == m ? 1 : 0) IO.select(LISTENERS, nil, nil, timeout/2.0) or next rescue Errno::EINTR retry rescue Errno::EBADF - alive = false + break end ret.first.each do |l| @@ -47,7 +47,12 @@ module Rainbows end threads.add(Thread.new(c) { |c| process_client(c) }) end - end + rescue + if alive + logger.error "Unhandled listen loop exception #{e.inspect}." + logger.error e.backtrace.join("\n") + end + end while alive && master_pid == Process.ppid join_spawned_threads(threads) end -- cgit v1.2.3-24-ge0c7