Commit 4598e0c3 authored by Robert Speicher's avatar Robert Speicher

Fix a potential timeout in `Gitlab::Logger.read_latest`

If this method was called for a file that didn't exist, we attempted to
first `build` it. But if the file wasn't writeable, such as a symlink
pointing to an unmounted filesystem, the method would just hang and
eventually timeout.

Further, this was entirely pointless since we were creating a file and
then shelling out to `tail`, eventually returning an empty Array. Now we
just skip building it and return the empty Array straight away.
parent 7965f4e7
...@@ -14,13 +14,9 @@ module Gitlab ...@@ -14,13 +14,9 @@ module Gitlab
def self.read_latest def self.read_latest
path = Rails.root.join("log", file_name) path = Rails.root.join("log", file_name)
self.build unless File.exist?(path)
tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path}))
tail_output.split("\n")
end
def self.read_latest_for(filename) return [] unless File.readable?(path)
path = Rails.root.join("log", filename)
tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path})) tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path}))
tail_output.split("\n") tail_output.split("\n")
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment