Commit 9c2baada authored by Stan Hu's avatar Stan Hu

Ignore Gitaly errors if cache flushing fails on project destruction

We should just ignore these errors and move along with the deletion
since the repositories are going to be trashed anyway.

Closes https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31164
parent 4fcd6900
...@@ -210,11 +210,20 @@ module Projects ...@@ -210,11 +210,20 @@ module Projects
end end
def flush_caches(project) def flush_caches(project)
project.repository.before_delete ignore_git_errors(repo_path) { project.repository.before_delete }
Repository.new(wiki_path, project, disk_path: repo_path).before_delete ignore_git_errors(wiki_path) { Repository.new(wiki_path, project, disk_path: repo_path).before_delete }
Projects::ForksCountService.new(project).delete_cache Projects::ForksCountService.new(project).delete_cache
end end
# If we get a Gitaly error, the repository may be corrupted. We can
# ignore these errors since we're going to trash the repositories
# anyway.
def ignore_git_errors(disk_path, &block)
yield
rescue Gitlab::Git::CommandError => e
Gitlab::GitLogger.warn(class: self.class.name, project_id: project.id, disk_path: disk_path, message: e.to_s)
end
end end
end end
---
title: Ignore Gitaly errors if cache flushing fails on project destruction
merge_request: 31164
author:
type: fixed
...@@ -121,7 +121,22 @@ describe Projects::DestroyService do ...@@ -121,7 +121,22 @@ describe Projects::DestroyService do
it { expect(Dir.exist?(remove_path)).to be_truthy } it { expect(Dir.exist?(remove_path)).to be_truthy }
end end
context 'when flushing caches fail' do context 'when flushing caches fail due to Git errors' do
before do
allow(project.repository).to receive(:before_delete).and_raise(::Gitlab::Git::CommandError)
allow(Gitlab::GitLogger).to receive(:warn).with(
class: described_class.name,
project_id: project.id,
disk_path: project.disk_path,
message: 'Gitlab::Git::CommandError').and_call_original
perform_enqueued_jobs { destroy_project(project, user, {}) }
end
it_behaves_like 'deleting the project'
end
context 'when flushing caches fail due to Redis' do
before do before do
new_user = create(:user) new_user = create(:user)
project.team.add_user(new_user, Gitlab::Access::DEVELOPER) project.team.add_user(new_user, Gitlab::Access::DEVELOPER)
......
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