From e794a40049959a23ba311c572e518bb7c2861812 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 24 Aug 2012 23:03:17 +0000 Subject: fiber/base: avoid negative sleep interval Also clarify the code while we're at it. Thanks to Lin Jen-Shin for pointing this out. ref: http://mid.gmane.org/CAA2_N1unOXb7Z4Jr8oKoSLu266O9Ko4o=oWzAcMA1w3=9X74KA@mail.gmail.com --- lib/rainbows/fiber/base.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb index 00af214..e8f5b16 100644 --- a/lib/rainbows/fiber/base.rb +++ b/lib/rainbows/fiber/base.rb @@ -51,8 +51,16 @@ module Rainbows::Fiber::Base end } fibs.each { |fib| fib.resume } - now = Time.now - max.nil? || max > (now + 1) ? 1 : max - now + + max_sleep = 1.0 # wake up semi-frequently to prevent SIGKILL from master + if max + max -= Time.now + return 0 if max < 0.0 + return max_sleep if max > max_sleep + max + else + max_sleep + end end def process(client) -- cgit v1.2.3-24-ge0c7