summaryrefslogtreecommitdiff
path: root/lib/gitlab_post_receive.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-05-10 14:39:52 -0700
committerStan Hu <stanhu@gmail.com>2016-05-10 14:43:04 -0700
commit63b711f8206964350816cd312050a12db82950dd (patch)
treeca5dc54813bd11389731bbfb2e3b0b9dafb59bc4 /lib/gitlab_post_receive.rb
parentf0f1bbec8ad5d5fade7c0efeee22ba9b9bc44f07 (diff)
downloadgitlab-shell-use-stdin.tar.gz
Pipe RPUSH command to Redis via stdin to avoid overrunning command-lineuse-stdin
Closes gitlab-org/gitlab-ce#17329
Diffstat (limited to 'lib/gitlab_post_receive.rb')
-rw-r--r--lib/gitlab_post_receive.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb
index 0fff479..20e46c5 100644
--- a/lib/gitlab_post_receive.rb
+++ b/lib/gitlab_post_receive.rb
@@ -2,6 +2,7 @@ require_relative 'gitlab_init'
require_relative 'gitlab_net'
require 'json'
require 'base64'
+require 'open3'
require 'securerandom'
class GitlabPostReceive
@@ -74,11 +75,20 @@ class GitlabPostReceive
queue = "#{config.redis_namespace}:queue:post_receive"
msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes], 'jid' => @jid })
- if system(*config.redis_command, 'rpush', queue, msg,
- err: '/dev/null', out: '/dev/null')
- return true
- else
- puts "GitLab: An unexpected error occurred (redis-cli returned #{$?.exitstatus})."
+
+ begin
+ result = Open3.popen2(*config.redis_command, '--pipe') do |stdin, stdout, wait_thr|
+ stdin.write("RPUSH '#{queue}' '#{msg}'")
+ stdin.close
+ wait_thr.value
+ end
+
+ return true if result == 0
+
+ puts "GitLab: An unexpected error occurred (redis-cli returned #{result.to_i})."
+ return false
+ rescue => e
+ puts "GitLab: An unexpected error occurred running redis-cli"
return false
end
end