Class: LogStash::ThreadWatchdog

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/threadwatchdog.rb

Defined Under Namespace

Classes: TimeoutError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(threads, watchdog_timeout = 10) ⇒ ThreadWatchdog

Returns a new instance of ThreadWatchdog.



12
13
14
15
# File 'lib/logstash/threadwatchdog.rb', line 12

def initialize(threads, watchdog_timeout=10)
  @threads = threads
  @watchdog_timeout = watchdog_timeout
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/logstash/threadwatchdog.rb', line 6

def logger
  @logger
end

#threadsObject

Returns the value of attribute threads.



7
8
9
# File 'lib/logstash/threadwatchdog.rb', line 7

def threads
  @threads
end

Instance Method Details

#watchObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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