diff options
author | Eric Wong <e@80x24.org> | 2013-10-19 23:43:59 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-20 00:09:04 +0000 |
commit | cd84e2ccbdf29b908c7d4711528d61bac05505bb (patch) | |
tree | 03e5cfd47e9a445094ccd559e2dd99095c0b422d /lib/yahns/queue_epoll.rb | |
parent | d4805769eb3174d25b429fa1faf5392b2669f354 (diff) | |
download | yahns-cd84e2ccbdf29b908c7d4711528d61bac05505bb.tar.gz |
Leaving running threads at exit seems to lead to occasional bugs at finalization on Ruby 2.0.0. This could be a bug with sleepy_penguin or kgio, too, so I'll have to investigate further. For now, we'll just destroy the IOs associated with each queue and let the threads die on their own. This changes the QueueEgg internals a bit and I've removed the unit test for QueueEgg now since the rest of the server already works well (and QueueEgg internals may change even more). Queues/worker threads no longer have their own logger, it seems like excessive configurability/complexity since acceptors do not have their own logger, either. This logger only exists to log bugs in yahns, not the application, so using the server logger is sufficient.
Diffstat (limited to 'lib/yahns/queue_epoll.rb')
-rw-r--r-- | lib/yahns/queue_epoll.rb | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/lib/yahns/queue_epoll.rb b/lib/yahns/queue_epoll.rb index 5cb455b..1813581 100644 --- a/lib/yahns/queue_epoll.rb +++ b/lib/yahns/queue_epoll.rb @@ -22,35 +22,33 @@ class Yahns::Queue < SleepyPenguin::Epoll::IO # :nodoc: end # returns an array of infinitely running threads - def spawn_worker_threads(logger, worker_threads, max_events) - worker_threads.times do - Thread.new do - Thread.current[:yahns_rbuf] = "" - begin - epoll_wait(max_events) do |_, io| # don't care for flags for now - case rv = io.yahns_step - when :wait_readable - epoll_ctl(Epoll::CTL_MOD, io, QEV_RD) - when :wait_writable - epoll_ctl(Epoll::CTL_MOD, io, QEV_WR) - when :wait_readwrite - epoll_ctl(Epoll::CTL_MOD, io, QEV_RDWR) - when :ignore # only used by rack.hijack - @fdmap.decr - when nil - # this is be the ONLY place where we call IO#close on - # things inside the queue - io.close - @fdmap.decr - else - raise "BUG: #{io.inspect}#yahns_step returned: #{rv.inspect}" - end + def worker_thread(logger, max_events) + Thread.new do + Thread.current[:yahns_rbuf] = "" + begin + epoll_wait(max_events) do |_, io| # don't care for flags for now + case rv = io.yahns_step + when :wait_readable + epoll_ctl(Epoll::CTL_MOD, io, QEV_RD) + when :wait_writable + epoll_ctl(Epoll::CTL_MOD, io, QEV_WR) + when :wait_readwrite + epoll_ctl(Epoll::CTL_MOD, io, QEV_RDWR) + when :ignore # only used by rack.hijack + @fdmap.decr + when nil + # this is be the ONLY place where we call IO#close on + # things inside the queue + io.close + @fdmap.decr + else + raise "BUG: #{io.inspect}#yahns_step returned: #{rv.inspect}" end - rescue => e - break if (IOError === e || Errno::EBADF === e) && closed? - Yahns::Log.exception(logger, 'queue loop', e) - end while true - end + end + rescue => e + break if closed? + Yahns::Log.exception(logger, 'queue loop', e) + end while true end end end |