Commit b8130d42 authored by Stan Hu's avatar Stan Hu

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
parents ec4fca69 57451f52
...@@ -7,13 +7,11 @@ module Gitlab ...@@ -7,13 +7,11 @@ module Gitlab
class_methods do class_methods do
def validator def validator
validator = Class.new(Node::Validator) @validator ||= Class.new(Node::Validator).tap do |validator|
if defined?(@validations) if defined?(@validations)
@validations.each { |rules| validator.class_eval(&rules) } @validations.each { |rules| validator.class_eval(&rules) }
end end
end
validator
end end
private private
......
...@@ -23,6 +23,10 @@ describe Gitlab::Ci::Config::Node::Validatable do ...@@ -23,6 +23,10 @@ describe Gitlab::Ci::Config::Node::Validatable do
.to be Gitlab::Ci::Config::Node::Validator .to be Gitlab::Ci::Config::Node::Validator
end 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 context 'when validating node instance' do
let(:node_instance) { node.new } let(:node_instance) { node.new }
......
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