Commit 2f4cbc3f authored by Stan Hu's avatar Stan Hu

Merge branch '249519-fix-daemon-jobs-hash-thread-safe-issue' into 'master'

Fix daemon memory killer jobs hash thread safety issue

Closes #249519

See merge request gitlab-org/gitlab!42468
parents d0a9c76c fe073ca6
---
title: Fix daemon memory killer jobs hash thread safety issue
merge_request: 42468
author:
type: fixed
...@@ -230,8 +230,10 @@ module Gitlab ...@@ -230,8 +230,10 @@ module Gitlab
end end
def rss_increase_by_jobs def rss_increase_by_jobs
Gitlab::SidekiqDaemon::Monitor.instance.jobs.sum do |job| # rubocop:disable CodeReuse/ActiveRecord Gitlab::SidekiqDaemon::Monitor.instance.jobs_mutex.synchronize do
rss_increase_by_job(job) Gitlab::SidekiqDaemon::Monitor.instance.jobs.sum do |job| # rubocop:disable CodeReuse/ActiveRecord
rss_increase_by_job(job)
end
end end
end end
......
...@@ -49,7 +49,7 @@ RSpec.describe Gitlab::SidekiqDaemon::MemoryKiller do ...@@ -49,7 +49,7 @@ RSpec.describe Gitlab::SidekiqDaemon::MemoryKiller do
expect { subject }.not_to raise_exception expect { subject }.not_to raise_exception
end end
it 'logs exception message once and raise execption and log stop message' do it 'logs exception message once and raise exception and log stop message' do
expect(Sidekiq.logger).to receive(:warn).once expect(Sidekiq.logger).to receive(:warn).once
.with( .with(
class: described_class.to_s, class: described_class.to_s,
...@@ -68,7 +68,7 @@ RSpec.describe Gitlab::SidekiqDaemon::MemoryKiller do ...@@ -68,7 +68,7 @@ RSpec.describe Gitlab::SidekiqDaemon::MemoryKiller do
pid: pid, pid: pid,
message: 'Stopping Gitlab::SidekiqDaemon::MemoryKiller Daemon') message: 'Stopping Gitlab::SidekiqDaemon::MemoryKiller Daemon')
expect { subject }.to raise_exception expect { subject }.to raise_exception(Exception, 'My Exception')
end end
it 'logs stop message once' do it 'logs stop message once' do
...@@ -402,12 +402,14 @@ RSpec.describe Gitlab::SidekiqDaemon::MemoryKiller do ...@@ -402,12 +402,14 @@ RSpec.describe Gitlab::SidekiqDaemon::MemoryKiller do
subject { memory_killer.send(:rss_increase_by_jobs) } subject { memory_killer.send(:rss_increase_by_jobs) }
it 'adds up individual rss_increase_by_job' do it 'adds up individual rss_increase_by_job' do
allow(Gitlab::SidekiqDaemon::Monitor).to receive_message_chain(:instance, :jobs_mutex, :synchronize).and_yield
expect(Gitlab::SidekiqDaemon::Monitor).to receive_message_chain(:instance, :jobs).and_return(running_jobs) expect(Gitlab::SidekiqDaemon::Monitor).to receive_message_chain(:instance, :jobs).and_return(running_jobs)
expect(memory_killer).to receive(:rss_increase_by_job).and_return(11, 22) expect(memory_killer).to receive(:rss_increase_by_job).and_return(11, 22)
expect(subject).to eq(33) expect(subject).to eq(33)
end end
it 'return 0 if no job' do it 'return 0 if no job' do
allow(Gitlab::SidekiqDaemon::Monitor).to receive_message_chain(:instance, :jobs_mutex, :synchronize).and_yield
expect(Gitlab::SidekiqDaemon::Monitor).to receive_message_chain(:instance, :jobs).and_return({}) expect(Gitlab::SidekiqDaemon::Monitor).to receive_message_chain(:instance, :jobs).and_return({})
expect(subject).to eq(0) expect(subject).to eq(0)
end end
......
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