summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-08-09 16:38:06 +0000
committerStan Hu <stanhu@gmail.com>2016-08-09 16:38:06 +0000
commitb8130d42c212a45ad1e568f191337f0bed0a3d01 (patch)
tree502501f102776cae994a70dc29f1df6e7e12b1cd
parentec4fca69355b3a9bb2acba4d943960a9acbcae2e (diff)
parent57451f52cdbd527a980c0df75e1ee8bb7897d2e9 (diff)
downloadgitlab-ce-b8130d42c212a45ad1e568f191337f0bed0a3d01.tar.gz
Merge branch 'fix/improve-ci-node-validatable-to-prevent-memory-leak' into 'master'
Memoize CI config node validator to prevent leaks ## What does this MR do? This MR memoizes CI configuration node validator, to prevent possible memory leak described in #20698. ## Why was this MR needed? See #20698 ## What are the relevant issue numbers? Closes #20698 ## Does this MR meet the acceptance criteria? - [ ] ~~[CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added~~ - [ ] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~ - [ ] ~~API support added~~ - Tests - [x] Added for this feature/bug - [x] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5733
-rw-r--r--lib/gitlab/ci/config/node/validatable.rb10
-rw-r--r--spec/lib/gitlab/ci/config/node/validatable_spec.rb4
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/gitlab/ci/config/node/validatable.rb b/lib/gitlab/ci/config/node/validatable.rb
index f6e2896dfb2..085e6e988d1 100644
--- a/lib/gitlab/ci/config/node/validatable.rb
+++ b/lib/gitlab/ci/config/node/validatable.rb
@@ -7,13 +7,11 @@ module Gitlab
class_methods do
def validator
- validator = Class.new(Node::Validator)
-
- if defined?(@validations)
- @validations.each { |rules| validator.class_eval(&rules) }
+ @validator ||= Class.new(Node::Validator).tap do |validator|
+ if defined?(@validations)
+ @validations.each { |rules| validator.class_eval(&rules) }
+ end
end
-
- validator
end
private
diff --git a/spec/lib/gitlab/ci/config/node/validatable_spec.rb b/spec/lib/gitlab/ci/config/node/validatable_spec.rb
index 10cd01afcd1..64b77fd6e03 100644
--- a/spec/lib/gitlab/ci/config/node/validatable_spec.rb
+++ b/spec/lib/gitlab/ci/config/node/validatable_spec.rb
@@ -23,6 +23,10 @@ describe Gitlab::Ci::Config::Node::Validatable do
.to be Gitlab::Ci::Config::Node::Validator
end
+ it 'returns only one validator to mitigate leaks' do
+ expect { node.validator }.not_to change { node.validator }
+ end
+
context 'when validating node instance' do
let(:node_instance) { node.new }