Categories
Uncategorized

TypeError: can’t convert ActiveSupport::Duration into time interval

Timeout::timeout(6.hours){}
TypeError: can't convert ActiveSupport::Duration into time interval

One of those stupid bugs that shows up in one environment, but not the other.
Both environments are running the exact same version of Ruby (1.8.7), Rails (2.3.4), and ActiveSupport (2.3.4)

The confusing thing is, on the environment where that works, this does NOT:

sleep(6.hours)

Which is the correct behavior. But why would Timeout::timeout work??

Looking through the ActiveSupport source yielded nothing of value.

I know the solution is:

Timeout::timeout(6.hours.to_i){}

But I just want to understand why.

UPDATE: I was wrong. I was using Ruby 1.8.7 vs Ruby 1.8.7 EE

In Ruby 1.8.7 EE, The Timeout::timeout method is different.

It does not raise from a failed sleep

      y = Thread.start {
        sleep sec
        x.raise exception, "execution expired" if x.alive?
      }

Like Ruby 1.8.7 does

    y = Thread.start {
      begin
        sleep sec
      rescue => e
        x.raise e
      else
        x.raise exception, "execution expired" if x.alive?
      end
    }