summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-05-23 17:09:04 +0900
committerShinya Maeda <shinya@gitlab.com>2018-05-28 14:34:37 +0900
commitd8fa256fa49f5582cad844138a7d72ac78f90fc2 (patch)
treefcf2a5ae5afe05ff6ff595d40ed7c9c58f73b5ae
parent014f5f6a69f63ee42bd94454108268f189b62b18 (diff)
downloadgitlab-ce-d8fa256fa49f5582cad844138a7d72ac78f90fc2.tar.gz
Add a monkey pach of https://github.com/carrierwaveuploader/carrierwave/pull/2314
-rw-r--r--config/initializers/carrierwave_monkey_patch.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/config/initializers/carrierwave_monkey_patch.rb b/config/initializers/carrierwave_monkey_patch.rb
new file mode 100644
index 00000000000..cbd055fb673
--- /dev/null
+++ b/config/initializers/carrierwave_monkey_patch.rb
@@ -0,0 +1,41 @@
+# This is a monkey patch until https://github.com/carrierwaveuploader/carrierwave/pull/2314 has been merged
+# This fixes a problem https://gitlab.com/gitlab-org/gitlab-ce/issues/46182 that carrierwave loads large files into memory
+# and triggers sidekiq shutdown by hitting RSS limit.
+module CarrierWave
+ module Storage
+ class Fog < Abstract
+ class File
+ def read
+ file_body = file.body
+
+ return if file_body.nil?
+ return file_body unless file_body.is_a?(::File)
+
+ begin
+ file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's closed
+ file_body.read
+ ensure
+ file_body.close
+ end
+ end
+
+ def store(new_file)
+ if new_file.is_a?(self.class)
+ new_file.copy_to(path)
+ else
+ fog_file = new_file.to_file
+ @content_type ||= new_file.content_type
+ @file = directory.files.create({
+ :body => fog_file ? fog_file : new_file.read,
+ :content_type => @content_type,
+ :key => path,
+ :public => @uploader.fog_public
+ }.merge(@uploader.fog_attributes))
+ fog_file.close if fog_file && !fog_file.closed?
+ end
+ true
+ end
+ end
+ end
+ end
+end