I have an app using ecto 3.3.2, ecto_sql 3.3.3, and postgrex 0.15.3. Everything’s been fine under Elixir 1.9.4 (OTP 22), but when I try to run my test suite under Elixir 1.10.0 or 1.10.11 (also OTP 22), I get the following error intermittently:
** (Postgrex.Error) ERROR 40P01 (deadlock_detected) deadlock detected
hint: See server log for query details.
Process 23951 waits for ShareLock on transaction 6852; blocked by process 23950.
Process 23950 waits for ShareLock on transaction 6867; blocked by process 23951.
The server log says:
ERROR: deadlock detected
DETAIL: Process 23951 waits for ShareLock on transaction 6852; blocked by process 23950.
Process 23950 waits for ShareLock on transaction 6867; blocked by process 23951.
Process 23951: INSERT INTO "works" ("accession_number","administrative_metadata","descriptive_metadata","published","visibility","work_type","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id"
Process 23950: INSERT INTO "works" ("accession_number","administrative_metadata","descriptive_metadata","published","visibility","work_type","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id"
HINT: See server log for query details.
CONTEXT: while inserting index tuple (0,13) in relation "works_accession_number_index"
STATEMENT: INSERT INTO "works" ("accession_number","administrative_metadata","descriptive_metadata","published","visibility","work_type","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id"
It’s not every time, and it’s not always on the same test(s). Has anyone else noticed any differences between Elixir 1.9 and 1.10 in this regard? Given that the error involves a transaction, and we use very few of them in our application code, I suspect this might have something to do with the Ecto SQL Sandbox?
MBK