diff options
author | Stan Hu <stanhu@gmail.com> | 2018-11-26 21:16:40 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-11-26 21:16:40 +0000 |
commit | deaf3af7e5f357f3e8d91f7f2d49ad3ce001ba68 (patch) | |
tree | 298ffe285c544ee73423f2bd63fe6f39ed12eeb8 /lib | |
parent | 7bbcd7b59baa5b442994a28e9cfc5888badc610f (diff) | |
parent | c150772edb65f727c9be0a82ec71c4b084c9d949 (diff) | |
download | gitlab-ce-deaf3af7e5f357f3e8d91f7f2d49ad3ce001ba68.tar.gz |
Merge branch 'fix-deadlock-chunked-io' into 'master'24280-last-commit-information-in-admin-project-view-is-not-accurate
Fix deadlock on ChunkedIO
See merge request gitlab-org/gitlab-ce!23329
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/trace/chunked_io.rb | 29 | ||||
-rw-r--r-- | lib/gitlab/http_io.rb | 8 |
2 files changed, 20 insertions, 17 deletions
diff --git a/lib/gitlab/ci/trace/chunked_io.rb b/lib/gitlab/ci/trace/chunked_io.rb index e9b3199d56e..8c6fd56493f 100644 --- a/lib/gitlab/ci/trace/chunked_io.rb +++ b/lib/gitlab/ci/trace/chunked_io.rb @@ -13,7 +13,7 @@ module Gitlab attr_reader :build attr_reader :tell, :size - attr_reader :chunk, :chunk_range + attr_reader :chunk_data, :chunk_range alias_method :pos, :tell @@ -75,14 +75,14 @@ module Gitlab until length <= 0 || eof? data = chunk_slice_from_offset - break if data.empty? + raise FailedToGetChunkError if data.empty? chunk_bytes = [CHUNK_SIZE - chunk_offset, length].min - chunk_data = data.byteslice(0, chunk_bytes) + chunk_data_slice = data.byteslice(0, chunk_bytes) - out << chunk_data - @tell += chunk_data.bytesize - length -= chunk_data.bytesize + out << chunk_data_slice + @tell += chunk_data_slice.bytesize + length -= chunk_data_slice.bytesize end out = out.join @@ -100,11 +100,14 @@ module Gitlab until eof? data = chunk_slice_from_offset + raise FailedToGetChunkError if data.empty? + new_line = data.index("\n") if !new_line.nil? - out << data[0..new_line] - @tell += new_line + 1 + raw_data = data[0..new_line] + out << raw_data + @tell += raw_data.bytesize break else out << data @@ -121,13 +124,13 @@ module Gitlab while tell < start_pos + data.bytesize # get slice from current offset till the end where it falls into chunk chunk_bytes = CHUNK_SIZE - chunk_offset - chunk_data = data.byteslice(tell - start_pos, chunk_bytes) + data_slice = data.byteslice(tell - start_pos, chunk_bytes) # append data to chunk, overwriting from that point - ensure_chunk.append(chunk_data, chunk_offset) + ensure_chunk.append(data_slice, chunk_offset) # move offsets within buffer - @tell += chunk_data.bytesize + @tell += data_slice.bytesize @size = [size, tell].max end @@ -183,12 +186,12 @@ module Gitlab current_chunk.tap do |chunk| raise FailedToGetChunkError unless chunk - @chunk = chunk.data + @chunk_data = chunk.data @chunk_range = chunk.range end end - @chunk[chunk_offset..CHUNK_SIZE] + @chunk_data.byteslice(chunk_offset, CHUNK_SIZE) end def chunk_offset diff --git a/lib/gitlab/http_io.rb b/lib/gitlab/http_io.rb index e768b8adb12..6a9fb85b054 100644 --- a/lib/gitlab/http_io.rb +++ b/lib/gitlab/http_io.rb @@ -85,11 +85,11 @@ module Gitlab break if data.empty? chunk_bytes = [BUFFER_SIZE - chunk_offset, length].min - chunk_data = data.byteslice(0, chunk_bytes) + data_slice = data.byteslice(0, chunk_bytes) - out << chunk_data - @tell += chunk_data.bytesize - length -= chunk_data.bytesize + out << data_slice + @tell += data_slice.bytesize + length -= data_slice.bytesize end out = out.join |