diff --git a/db/fixtures/development/13_comments.rb b/db/fixtures/development/13_comments.rb index f19beaefcb7a8f6f1f6b6f087bb417531415715f..519d91af0c11c387ee8f3953930eae3099a04ed2 100644 --- a/db/fixtures/development/13_comments.rb +++ b/db/fixtures/development/13_comments.rb @@ -1,7 +1,7 @@ require './spec/support/sidekiq_middleware' Gitlab::Seeder.quiet do - Issue.find_each do |issue| + Gitlab::Seeder.parallel_each(Issue.preload(:project).all) do |issue| project = issue.project project.team.users.each do |user| @@ -18,7 +18,7 @@ end end - MergeRequest.find_each do |mr| + Gitlab::Seeder.parallel_each(MergeRequest.all) do |mr| project = mr.project project.team.users.each do |user| diff --git a/lib/gitlab/seeder.rb b/lib/gitlab/seeder.rb index e2c8c0ccdd011289ec39e8877861d0c45a41f765..8b1cc6785220775c3161b0f3a490dfbc9a10b950 100644 --- a/lib/gitlab/seeder.rb +++ b/lib/gitlab/seeder.rb @@ -45,6 +45,21 @@ module UserSeed end end + def self.parallel_each(array) + raise 'Nested Gitlab::Seeder.parallel_each calls are not allowed.' if @parallel + + @parallel = true + + # Closing gRPC channels before forking prevents segfaults when Ruby + # finalizes inherited gRPC objects in the child process. + # See https://gitlab.com/gitlab-org/gitlab/-/issues/480716#note_2787476778 + Gitlab::GitalyClient.clear_stubs! + + Parallel.each(array, in_processes: Parallel.processor_count) { |record| yield(record) } + ensure + @parallel = false + end + def self.log_message(message) puts "#{Time.current}: #{message}" end