make stat socket much more robust
This commit is contained in:
parent
e189ec2def
commit
b077335a30
|
@ -38,16 +38,31 @@ class StatsSocket
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
start = Time.now
|
||||||
|
line = ""
|
||||||
|
|
||||||
|
while Time.now - start < 10
|
||||||
if IO.select(nil, [socket], nil, 10)
|
if IO.select(nil, [socket], nil, 10)
|
||||||
line = socket.read_nonblock(1000)
|
begin
|
||||||
|
line << socket.read_nonblock(1000)
|
||||||
|
rescue IO::WaitReadable
|
||||||
|
sleep 0.001
|
||||||
|
end
|
||||||
|
end
|
||||||
|
break if line.include?("\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
if line.include?("\n")
|
||||||
socket.write get_response(line.strip)
|
socket.write get_response(line.strip)
|
||||||
end
|
end
|
||||||
socket.close
|
|
||||||
true
|
true
|
||||||
rescue IOError
|
rescue IOError => e
|
||||||
# nothing to do here, case its normal on shutdown
|
# nothing to do here, case its normal on shutdown
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.warn("Failed to handle connection in stats socket #{e}")
|
Rails.logger.warn("Failed to handle connection in stats socket #{e}")
|
||||||
|
ensure
|
||||||
|
socket&.close rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_response(command)
|
def get_response(command)
|
||||||
|
|
|
@ -29,6 +29,14 @@ describe StatsSocket do
|
||||||
socket.close
|
socket.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
socket = UNIXSocket.new(socket_path)
|
||||||
|
socket.send "gc_st", 0
|
||||||
|
socket.flush
|
||||||
|
sleep 0.001
|
||||||
|
socket.send "at\n", 0
|
||||||
|
line = socket.readline
|
||||||
|
socket.close
|
||||||
|
|
||||||
parsed = JSON.parse(line)
|
parsed = JSON.parse(line)
|
||||||
|
|
||||||
expect(parsed.keys.sort).to eq(GC.stat.keys.map(&:to_s).sort)
|
expect(parsed.keys.sort).to eq(GC.stat.keys.map(&:to_s).sort)
|
||||||
|
|
Loading…
Reference in New Issue