class LogStash::ThreadWatchdog

Attributes

logger[RW]
threads[RW]

Public Class Methods

new(threads, watchdog_timeout=10) click to toggle source
# File lib/logstash/threadwatchdog.rb, line 12
def initialize(threads, watchdog_timeout=10)
  @threads = threads
  @watchdog_timeout = watchdog_timeout
end

Public Instance Methods

watch() click to toggle source
# File lib/logstash/threadwatchdog.rb, line 18
def watch
  while sleep(1)
    cutoff = Time.now - @watchdog_timeout
    @threads.each do |t|
      watchdog = t[:watchdog]
      if watchdog and watchdog <= cutoff
        age = Time.now - watchdog
        @logger.fatal("thread watchdog timeout",
                      :thread => t,
                      :backtrace => t.backtrace,
                      :thread_watchdog => watchdog,
                      :age => age,
                      :cutoff => @watchdog_timeout,
                      :state => t[:watchdog_state])
        raise TimeoutError, "watchdog timeout"
      end
    end
  end
end