timeout-race-fix.patch

Motohiro KOSAKI, 01/17/2011 01:53 PM

Download (2.94 KB)

View differences:

lib/timeout.rb
44 44
    return yield(sec) if sec == nil or sec.zero?
45 45
    exception = klass || Class.new(ExitException)
46 46
    begin
47
      x = Thread.current
48
      y = Thread.start {
49
        begin
50
          sleep sec
51
        rescue => e
52
          x.raise e
53
        else
54
          x.raise exception, "execution expired" if x.alive?
47
      begin
48
        x = Thread.current
49
        y = Thread.start {
50
          begin
51
            sleep sec
52
          rescue => e
53
            x.raise e
54
          else
55
            x.raise exception, "execution expired"
56
          end
57
        }
58
        return yield(sec)
59
      ensure
60
        if y
61
          y.kill
62
          y.join # make sure y is dead.
55 63
        end
56
      }
57
      return yield(sec)
64
      end
58 65
    rescue exception => e
59 66
      rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
60 67
      (bt = e.backtrace).reject! {|m| rej =~ m}
......
66 73
      raise if klass            # if exception class is specified, it
67 74
                                # would be expected outside.
68 75
      raise Error, e.message, e.backtrace
69
    ensure
70
      if y and y.alive?
71
        y.kill
72
        y.join # make sure y is dead.
73
      end
74 76
    end
75 77
  end
76 78

  
77
-