negative timeout in Rainbows::Fiber::Base

Lin Jen-Shin (godfat) godfat at godfat.org
Thu Aug 23 20:36:24 UTC 2012


Greetings Unicorns,

I am writing some stupid benchmarks, trying FiberSpawn and
FiberPool, and seeing this error:

    listen loop error: time interval must be positive (ArgumentError)

Looking into the code, in this line:
http://bogomips.org/rainbows.git/tree/lib/rainbows/fiber/base.rb#n55
Isn't that possible `max <= (now + 1)` and `now > max`?
Whenever this is the case, then timeout passed to `select`
could be negative. I am not sure how to fix this correctly,
but a blind `abs` could resolve this error.

Hope this could give some hints, thank you!

commit b599374ef10c7847445f29f80e74cde3e4d3b940
Author: Lin Jen-Shin <godfat at godfat.org>
Date:   Fri Aug 24 04:33:38 2012 +0800

    fiber/base.rb: make timeout never be negative.

    In the case where `max <= (now + 1)` and `now > max`,
    we need to make sure that timeout is positive.

diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb
index 00af214..7bd43cb 100644
--- a/lib/rainbows/fiber/base.rb
+++ b/lib/rainbows/fiber/base.rb
@@ -52,7 +52,7 @@ module Rainbows::Fiber::Base
     }
     fibs.each { |fib| fib.resume }
     now = Time.now
-    max.nil? || max > (now + 1) ? 1 : max - now
+    max.nil? || max > (now + 1) ? 1 : (max - now).abs
   end

   def process(client)


More information about the rainbows-talk mailing list