Project

General

Profile

Actions

Bug #32086

closed

db seed triggered by sidekiq resulting in duplicate provisioning-templates

Added by Markus Bucher almost 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
High
Assignee:
-
Category:
Database
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

We had the problem that after adding templates in `app/views/unattended/..` and restarting services with `foreman-maintain service restart`, we ended up with the templates having been added multiple times.

I added an Exception in the seeding code and found out that the seed is not only started by foreman.service startup, but also by sidekiq processes.
Probably because sidekiq also includes foreman config and therefore also `config/initializers/seeds.rb`.

The seeding-code ran so simultaneous that the new templates were added multiple times.

Stack-Trace for the seed triggered by `sidekiq`:

2021-03-12T19:00:58 [E|app|] Error while attempting to seed database, please run `foreman-rake db:seed` manually!
2021-03-12T19:00:58 [E|app|] /usr/share/foreman/lib/seed_helper.rb:109:in `import_raw_template': Called IT :-) (RuntimeError)
    from /usr/share/foreman/lib/seed_helper.rb:144:in `block in import_templates'
    from /usr/share/foreman/lib/seed_helper.rb:143:in `each'
    from /usr/share/foreman/lib/seed_helper.rb:143:in `import_templates'
    from /usr/share/foreman/db/seeds.d/070-provisioning_templates.rb:9:in `block in <top (required)>'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.9.0/lib/audited/auditor.rb:376:in `without_auditing'
    from /usr/share/foreman/db/seeds.d/070-provisioning_templates.rb:2:in `<top (required)>'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:318:in `load'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:318:in `block in load'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:318:in `load'
    from /usr/share/foreman/app/services/foreman_seeder.rb:57:in `block (2 levels) in execute'
    from /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:108:in `as'
    from /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:114:in `as_anonymous_admin'
    from /usr/share/foreman/app/services/foreman_seeder.rb:56:in `block in execute'
    from /usr/share/foreman/app/services/foreman_seeder.rb:49:in `each'
    from /usr/share/foreman/app/services/foreman_seeder.rb:49:in `execute'
    from /usr/share/foreman/config/initializers/seeds.rb:13:in `block (2 levels) in <top (required)>'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:68:in `block in execute_hook'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/application/finisher.rb:129:in `block in <module:Finisher>'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/initializable.rb:32:in `instance_exec'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/initializable.rb:32:in `run'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:228:in `block in tsort_each'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:431:in `each_strongly_connected_component_from'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:349:in `block in each_strongly_connected_component'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:347:in `each'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:347:in `call'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:347:in `each_strongly_connected_component'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:226:in `tsort_each'
    from /opt/rh/rh-ruby25/root/usr/share/ruby/tsort.rb:205:in `tsort_each'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/initializable.rb:60:in `run_initializers'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/application.rb:363:in `initialize!'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/railtie.rb:190:in `public_send'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.1/lib/rails/railtie.rb:190:in `method_missing'
    from /usr/share/foreman/config/environment.rb:5:in `<top (required)>'
    from /opt/rh/rh-ruby25/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /opt/rh/rh-ruby25/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require'
    from /usr/share/foreman/extras/dynflow-sidekiq.rb:9:in `<top (required)>'
    from /opt/rh/rh-ruby25/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /opt/rh/rh-ruby25/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:292:in `boot_system'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:46:in `run'
    from /opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/bin/sidekiq:12:in `<top (required)>'
    from /opt/theforeman/tfm/root/usr/bin/sidekiq:23:in `load'
    from /opt/theforeman/tfm/root/usr/bin/sidekiq:23:in `<main>'


Related issues 2 (0 open2 closed)

Related to Katello - Bug #32277: Seed fails with PG::ForeignKeyViolation: ERROR: insert or update on table "foreman_tasks_tasks" violates foreign key constraint "fk_rails_a56904dd86"ClosedJonathon TurelActions
Related to Foreman - Bug #32657: Upgrade fails with error Validation failed: Name has already been taken at db:seed stageClosedTomer BriskerActions
Actions

Also available in: Atom PDF