Project

General

Profile

Actions

Bug #12193

closed

Deadlock occuring when creating host

Added by Stefan Julin over 8 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Database
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

The following happens quite often when trying to insert to nics table when creating a new host:

2015-10-15 11:55:40 [app] [W] Action failed
 | ActiveRecord::StatementInvalid: PGError: ERROR:  deadlock detected
 | DETAIL:  Process 15662 waits for ExclusiveLock on tuple (8,16) of relation 16
559 of database 16384; blocked by process 20700.
 | Process 20700 waits for ShareLock on transaction 299626203; blocked by proces
s 15662.
 | HINT:  See server log for query details.
 | : UPDATE "domains" SET "hosts_count" = COALESCE("hosts_count", 0) + 1 WHERE " 
domains"."id" IN (SELECT "domains"."id" FROM "domains"  WHERE "domains"."id" = 2
 ORDER BY domains.name)
 | /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record
/connection_adapters/postgresql_adapter.rb:1158:in `async_exec'
..
/associations/builder/belongs_to.rb:30:in `block in add_counter_cache_callbacks'
 | /usr/share/foreman/app/models/nic/base.rb:61:in `belongs_to_counter_cache_after_create_for_domain'
... 
 | /usr/share/foreman/app/models/concerns/foreman/sti.rb:29:in `save_with_type'
 | /usr/share/foreman/app/controllers/hosts_controller.rb:84:in `create'
...
 | /usr/share/foreman/app/controllers/concerns/application_shared.rb:13:in `set_
timezone'
[2015-10-14 07:43:19.739 CEST] [12290]: LOG:  process 12290 still waiting for ShareLock on transaction 299488065 after 1000.100 ms
[2015-10-14 07:43:19.739 CEST] [12290]: CONTEXT:  SQL statement "SELECT 1 FROM ONLY "public"."operatingsystems" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x" 
...
[2015-10-14 07:46:06.028 CEST] [10305]: LOG:  process 10305 still waiting for ShareLock on transaction 299488065 after 1000.123 ms
[2015-10-14 07:46:06.028 CEST] [10305]: STATEMENT:  UPDATE "domains" SET "hosts_count" = COALESCE("hosts_count", 0) - 1 WHERE "domains"."id" IN (SELECT "domains"."id" FROM "domains"  WHERE "domains"."id" = 2 ORDER BY domains.name)
...
[2015-10-14 07:50:21.695 CEST] [12248]: DETAIL:  Process 12248 waits for ShareLock on transaction 299488070; blocked by process 10305.
        Process 10305 waits for ShareLock on transaction 299488101; blocked by process 12248.
        Process 12248: INSERT INTO "nics" ("attached_devices", "attached_to", "attrs", "bond_options", "compute_attributes", "created_at", "domain_id", "host_id", "identifier", "ip", "link", "mac", "managed", "mode", "name", "password", "primary", "provider", "provision", "subnet_id", "tag", "type", "updated_at", "username", "virtual") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25) RETURNING "id" 
        Process 10305: UPDATE "architectures" SET "hosts_count" = COALESCE("hosts_count", 0) - 1 WHERE "architectures"."id" = 1
[2015-10-14 07:50:21.695 CEST] [12248]: HINT:  See server log for query details.
[2015-10-14 07:50:21.695 CEST] [12248]: CONTEXT:  SQL statement "SELECT 1 FROM ONLY "public"."domains" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x" 
[2015-10-14 07:50:21.695 CEST] [12248]: STATEMENT:  INSERT INTO "nics" ("attached_devices", "attached_to", "attrs", "bond_options", "compute_attributes", "created_at", "domain_id", "host_id", "identifier", "ip", "link", "mac", "managed", "mode", "name", "password", "primary", "provider", "provision", "subnet_id", "tag", "type", "updated_at", "username", "virtual") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25) RETURNING "id" 
[2015-10-14 07:50:22.640 CEST] [12256]: LOG:  process 12256 still waiting for ShareLock on transaction 299488094

We are on postgresql version 8.4.20.

Tomer Brisker told me this:

Looks like ufortunatley rails doesn't allow an after_commit callback, which would update in a different transaction and prevent deadlocks

I applied the patch in http://projects.theforeman.org/issues/5990 but it did not help. We were previously on foreman 1.6.3 and there we did not see any share locks and hanging queries against the database.


Related issues 6 (0 open6 closed)

Related to Foreman - Bug #11444: Domains page shows negative number of hostsClosedTomer Brisker08/21/2015Actions
Related to Foreman - Refactor #12484: Remove useless host group countersResolvedTomer Brisker11/15/2015Actions
Related to Foreman - Bug #11741: Config group host counter not incremented on host creation with associationResolved09/09/2015Actions
Related to Foreman - Bug #16622: ActiveRecord::StatementInvalid exception when accessing Hosts->Operating systems with restricted accessResolvedBrandon Weeks09/20/2016Actions
Related to Foreman - Bug #17666: Upgrade fails during db:migrationClosedTomer Brisker12/13/2016Actions
Related to Foreman - Bug #18260: Choose different org will result in the same org's host number change in organizations pageClosedDaniel Lobato Garcia01/26/2017Actions
Actions

Also available in: Atom PDF