Skip to content

Comments

Fix lock leak on PostgreSQL 12 and later#298

Merged
siegy22 merged 4 commits intoque-rb:masterfrom
ennova:postgresql-12
Jan 26, 2021
Merged

Fix lock leak on PostgreSQL 12 and later#298
siegy22 merged 4 commits intoque-rb:masterfrom
ennova:postgresql-12

Conversation

@jasoncodes
Copy link
Contributor

Fixes #290.

PostgreSQL 12 and later do not materialise all CTEs automatically. This can result in multiple scans occurring which in turn can result in pg_try_advisory_lock being invoked multiple times on the same job. This results in a leak as we only call unlock once. This PR forces the CTE in the locker to be materialised which matches pre-PostgreSQL 12 behaviour.

I wasn’t able to reproduce any similar issues with the polling code but it’s possible the same issue exists there. I suspect the lock_taken CTE being used twice in lock_and_update_priorities is enough to trigger the materialisation path there.

This PR also fixes the use of an obsolete column in pg_attrdef which was preventing a green build on PostgreSQL 12.

PostgreSQL 12 drops this obsolete column.

https://www.postgresql.org/docs/12/release-12.html:
> Remove obsolete pg_attrdef.adsrc column (Peter Eisentraut)
>
> This column has been deprecated for a long time, because it
> did not update in response to other catalog changes (such as
> column renamings). The recommended way to get a text version
> of a default-value expression from `pg_attrdef` is
> `pg_get_expr(adbin, adrelid)`.
PostgreSQL 12 and later do not materialise all CTEs automatically.
This can result in multiple scans occurring which in turn can
result in `pg_try_advisory_lock` being invoked multiple times on
the same job. This results in a leak as we only call unlock once.
@siegy22
Copy link
Member

siegy22 commented Jan 26, 2021

Thank you very much! 💚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Locker doesn't release locks for processed jobs under some circumstances

2 participants