PG::TRDeadlockDetected: ERROR: deadlock detected



Has anyone else experienced this error when specs are run on CircleCI?

PG::TRDeadlockDetected: ERROR: deadlock detected

It goes on to say…

DETAIL:  Process 11443 waits for AccessShareLock on relation 16956 of database 16634; blocked by process 11330.
   Process 11330 waits for AccessExclusiveLock on relation 17200 of database 16634; blocked by process 11443.
   HINT:  See server log for query details.
   : SELECT COUNT(DISTINCT "units"."id") FROM "units" LEFT OUTER JOIN "unit_meta_data" ON "unit_meta_data"."unit_id" = "units"."id" LEFT OUTER JOIN "locations" ON "locations"."id" = "units"."location_id" LEFT OUTER JOIN "unit_photos" ON "unit_photos"."unit_id" = "units"."id" WHERE "units"."owner_id" = $1

I’m leaving my query in, incase it provide some sort of insight. This doesn’t seem to occur in production or any other environment, just semi-periodically when tests are run.


A deadlock usually happens when a table is not available due to some other query blocking it, what are the previous few queries that are run in your testing suite?


Yes, I’m running into the same issue with a host of different queries in a Rails app during Capybara feature specs.