I recently added the gem to a project and we ran into a case where the locks were not getting freed due to the transaction being aborted when it hit a configured statement timeout. When the abort occurred ActiveRecord would throw PG::InFailedSqlTransaction when trying to do the unlock.
We monkey patched in pg_try_advisory_xact_lock which auto releases at the end of the transaction and it has been working well so far. I'm fairly new to advisory locks so there might be a reason not to use them. From what I understand the main issues are that pg_try_advisory_lock will work outside of a transaction and pg_try_advisory_xact_lock is only supported in PostgreSQL 9.1 and up.
I recently added the gem to a project and we ran into a case where the locks were not getting freed due to the transaction being aborted when it hit a configured statement timeout. When the abort occurred ActiveRecord would throw
PG::InFailedSqlTransactionwhen trying to do the unlock.We monkey patched in
pg_try_advisory_xact_lockwhich auto releases at the end of the transaction and it has been working well so far. I'm fairly new to advisory locks so there might be a reason not to use them. From what I understand the main issues are thatpg_try_advisory_lockwill work outside of a transaction andpg_try_advisory_xact_lockis only supported in PostgreSQL 9.1 and up.