8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/micron/runner/process_reaper.rb', line 8
def self.create(test)
Thread.new(test) { |test|
Thread.current[:name] = "reaper-#{test.pid}"
debug "started"
err = 0
sel = 0
open = false
while true
if test.wait_nonblock then
break
end
begin
if err > 10 then debug "Unleash the reaper!!"
Process.kill(9, test.pid)
break
end
if !open then
if IO.select([test.err], nil, nil, 1).nil? then
sel += 1
debug "select = #{sel}"
err += 1 if err > 0
debug "err = #{err}"
Thread.pass
next
end
debug "opened err io"
open = true
end
str = test.err.read_nonblock(1024*16)
debug str if !str.nil?
if !str.nil? &&
(str.include?("malloc: *** error for object") ||
str.include?("Segmentation fault")) then
debug "looks like we got an error"
err = 1
end
rescue EOFError
debug "caught EOFError"
err = 1
if test.wait_nonblock then
debug "hang watcher exiting since it looks like process exited also"
break
end
rescue Errno::EWOULDBLOCK
open = false
next
rescue Exception => ex
debug "caught another ex?!"
debug Micron.dump_ex(ex, true)
err = 1
end
if err > 0 then
err += 1
sleep 0.1
end
end
reapers.delete(Thread.current)
debug "thread exiting"
}
end
|