pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
@ 2025-08-19 06:00  Amit Kapila <akapila@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Amit Kapila @ 2025-08-19 06:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix self-deadlock during DROP SUBSCRIPTION.

The DROP SUBSCRIPTION command performs several operations: it stops the
subscription workers, removes subscription-related entries from system
catalogs, and deletes the replication slot on the publisher server.
Previously, this command acquired an AccessExclusiveLock on
pg_subscription before initiating these steps.

However, while holding this lock, the command attempts to connect to the
publisher to remove the replication slot. In cases where the connection is
made to a newly created database on the same server as subscriber, the
cache-building process during connection tries to acquire an
AccessShareLock on pg_subscription, resulting in a self-deadlock.

To resolve this issue, we reduce the lock level on pg_subscription during
DROP SUBSCRIPTION from AccessExclusiveLock to RowExclusiveLock. Earlier,
the higher lock level was used to prevent the launcher from starting a new
worker during the drop operation, as a restarted worker could become
orphaned.

Now, instead of relying on a strict lock, we acquire an AccessShareLock on
the specific subscription being dropped and re-validate its existence
after acquiring the lock. If the subscription is no longer valid, the
worker exits gracefully. This approach avoids the deadlock while still
ensuring that orphan workers are not created.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/18988-7312c868be2d467f@postgresql.org

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a5d4c04150d4c5a946702734917222af7364204b

Modified Files
--------------
src/backend/commands/subscriptioncmds.c  |  8 +++++---
src/backend/replication/logical/worker.c |  7 +++++++
src/test/subscription/t/100_bugs.pl      | 30 ++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
@ 2025-08-19 06:00  Amit Kapila <akapila@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Amit Kapila @ 2025-08-19 06:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix self-deadlock during DROP SUBSCRIPTION.

The DROP SUBSCRIPTION command performs several operations: it stops the
subscription workers, removes subscription-related entries from system
catalogs, and deletes the replication slot on the publisher server.
Previously, this command acquired an AccessExclusiveLock on
pg_subscription before initiating these steps.

However, while holding this lock, the command attempts to connect to the
publisher to remove the replication slot. In cases where the connection is
made to a newly created database on the same server as subscriber, the
cache-building process during connection tries to acquire an
AccessShareLock on pg_subscription, resulting in a self-deadlock.

To resolve this issue, we reduce the lock level on pg_subscription during
DROP SUBSCRIPTION from AccessExclusiveLock to RowExclusiveLock. Earlier,
the higher lock level was used to prevent the launcher from starting a new
worker during the drop operation, as a restarted worker could become
orphaned.

Now, instead of relying on a strict lock, we acquire an AccessShareLock on
the specific subscription being dropped and re-validate its existence
after acquiring the lock. If the subscription is no longer valid, the
worker exits gracefully. This approach avoids the deadlock while still
ensuring that orphan workers are not created.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/18988-7312c868be2d467f@postgresql.org

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e41137155869da54118cfe80a1300a73bde58d61

Modified Files
--------------
src/backend/commands/subscriptioncmds.c  |  8 +++++---
src/backend/replication/logical/worker.c |  7 +++++++
src/test/subscription/t/100_bugs.pl      | 30 ++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
@ 2025-08-19 06:00  Amit Kapila <akapila@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Amit Kapila @ 2025-08-19 06:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix self-deadlock during DROP SUBSCRIPTION.

The DROP SUBSCRIPTION command performs several operations: it stops the
subscription workers, removes subscription-related entries from system
catalogs, and deletes the replication slot on the publisher server.
Previously, this command acquired an AccessExclusiveLock on
pg_subscription before initiating these steps.

However, while holding this lock, the command attempts to connect to the
publisher to remove the replication slot. In cases where the connection is
made to a newly created database on the same server as subscriber, the
cache-building process during connection tries to acquire an
AccessShareLock on pg_subscription, resulting in a self-deadlock.

To resolve this issue, we reduce the lock level on pg_subscription during
DROP SUBSCRIPTION from AccessExclusiveLock to RowExclusiveLock. Earlier,
the higher lock level was used to prevent the launcher from starting a new
worker during the drop operation, as a restarted worker could become
orphaned.

Now, instead of relying on a strict lock, we acquire an AccessShareLock on
the specific subscription being dropped and re-validate its existence
after acquiring the lock. If the subscription is no longer valid, the
worker exits gracefully. This approach avoids the deadlock while still
ensuring that orphan workers are not created.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/18988-7312c868be2d467f@postgresql.org

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7ece7612906e0ce9fe6d38b7b68f6176857c79f9

Modified Files
--------------
src/backend/commands/subscriptioncmds.c  |  8 +++++---
src/backend/replication/logical/worker.c |  7 +++++++
src/test/subscription/t/100_bugs.pl      | 30 ++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
@ 2025-08-19 06:00  Amit Kapila <akapila@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Amit Kapila @ 2025-08-19 06:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix self-deadlock during DROP SUBSCRIPTION.

The DROP SUBSCRIPTION command performs several operations: it stops the
subscription workers, removes subscription-related entries from system
catalogs, and deletes the replication slot on the publisher server.
Previously, this command acquired an AccessExclusiveLock on
pg_subscription before initiating these steps.

However, while holding this lock, the command attempts to connect to the
publisher to remove the replication slot. In cases where the connection is
made to a newly created database on the same server as subscriber, the
cache-building process during connection tries to acquire an
AccessShareLock on pg_subscription, resulting in a self-deadlock.

To resolve this issue, we reduce the lock level on pg_subscription during
DROP SUBSCRIPTION from AccessExclusiveLock to RowExclusiveLock. Earlier,
the higher lock level was used to prevent the launcher from starting a new
worker during the drop operation, as a restarted worker could become
orphaned.

Now, instead of relying on a strict lock, we acquire an AccessShareLock on
the specific subscription being dropped and re-validate its existence
after acquiring the lock. If the subscription is no longer valid, the
worker exits gracefully. This approach avoids the deadlock while still
ensuring that orphan workers are not created.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/18988-7312c868be2d467f@postgresql.org

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ef77502746fed4cca0ea8ab45c95f56ef55a95e5

Modified Files
--------------
src/backend/commands/subscriptioncmds.c  |  8 +++++---
src/backend/replication/logical/worker.c |  7 +++++++
src/test/subscription/t/100_bugs.pl      | 32 +++++++++++++++++++++++++++++++-
3 files changed, 43 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
@ 2025-08-19 06:00  Amit Kapila <akapila@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Amit Kapila @ 2025-08-19 06:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix self-deadlock during DROP SUBSCRIPTION.

The DROP SUBSCRIPTION command performs several operations: it stops the
subscription workers, removes subscription-related entries from system
catalogs, and deletes the replication slot on the publisher server.
Previously, this command acquired an AccessExclusiveLock on
pg_subscription before initiating these steps.

However, while holding this lock, the command attempts to connect to the
publisher to remove the replication slot. In cases where the connection is
made to a newly created database on the same server as subscriber, the
cache-building process during connection tries to acquire an
AccessShareLock on pg_subscription, resulting in a self-deadlock.

To resolve this issue, we reduce the lock level on pg_subscription during
DROP SUBSCRIPTION from AccessExclusiveLock to RowExclusiveLock. Earlier,
the higher lock level was used to prevent the launcher from starting a new
worker during the drop operation, as a restarted worker could become
orphaned.

Now, instead of relying on a strict lock, we acquire an AccessShareLock on
the specific subscription being dropped and re-validate its existence
after acquiring the lock. If the subscription is no longer valid, the
worker exits gracefully. This approach avoids the deadlock while still
ensuring that orphan workers are not created.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/18988-7312c868be2d467f@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0a98f24a65cdf8520b6b36154f8b425e85b78854

Modified Files
--------------
src/backend/commands/subscriptioncmds.c  |  8 +++++---
src/backend/replication/logical/worker.c |  7 +++++++
src/test/subscription/t/100_bugs.pl      | 32 +++++++++++++++++++++++++++++++-
3 files changed, 43 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
@ 2025-08-19 06:00  Amit Kapila <akapila@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Amit Kapila @ 2025-08-19 06:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix self-deadlock during DROP SUBSCRIPTION.

The DROP SUBSCRIPTION command performs several operations: it stops the
subscription workers, removes subscription-related entries from system
catalogs, and deletes the replication slot on the publisher server.
Previously, this command acquired an AccessExclusiveLock on
pg_subscription before initiating these steps.

However, while holding this lock, the command attempts to connect to the
publisher to remove the replication slot. In cases where the connection is
made to a newly created database on the same server as subscriber, the
cache-building process during connection tries to acquire an
AccessShareLock on pg_subscription, resulting in a self-deadlock.

To resolve this issue, we reduce the lock level on pg_subscription during
DROP SUBSCRIPTION from AccessExclusiveLock to RowExclusiveLock. Earlier,
the higher lock level was used to prevent the launcher from starting a new
worker during the drop operation, as a restarted worker could become
orphaned.

Now, instead of relying on a strict lock, we acquire an AccessShareLock on
the specific subscription being dropped and re-validate its existence
after acquiring the lock. If the subscription is no longer valid, the
worker exits gracefully. This approach avoids the deadlock while still
ensuring that orphan workers are not created.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/18988-7312c868be2d467f@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/aa21e49225a1b4f8465dee5a9410e52b5a889f90

Modified Files
--------------
src/backend/commands/subscriptioncmds.c  |  8 +++++---
src/backend/replication/logical/worker.c |  7 +++++++
src/test/subscription/t/100_bugs.pl      | 30 ++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix self-deadlock during DROP SUBSCRIPTION.
@ 2025-08-19 06:00  Amit Kapila <akapila@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Amit Kapila @ 2025-08-19 06:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix self-deadlock during DROP SUBSCRIPTION.

The DROP SUBSCRIPTION command performs several operations: it stops the
subscription workers, removes subscription-related entries from system
catalogs, and deletes the replication slot on the publisher server.
Previously, this command acquired an AccessExclusiveLock on
pg_subscription before initiating these steps.

However, while holding this lock, the command attempts to connect to the
publisher to remove the replication slot. In cases where the connection is
made to a newly created database on the same server as subscriber, the
cache-building process during connection tries to acquire an
AccessShareLock on pg_subscription, resulting in a self-deadlock.

To resolve this issue, we reduce the lock level on pg_subscription during
DROP SUBSCRIPTION from AccessExclusiveLock to RowExclusiveLock. Earlier,
the higher lock level was used to prevent the launcher from starting a new
worker during the drop operation, as a restarted worker could become
orphaned.

Now, instead of relying on a strict lock, we acquire an AccessShareLock on
the specific subscription being dropped and re-validate its existence
after acquiring the lock. If the subscription is no longer valid, the
worker exits gracefully. This approach avoids the deadlock while still
ensuring that orphan workers are not created.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/18988-7312c868be2d467f@postgresql.org

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/288a817bcb04c896c8e3489d106285995489358d

Modified Files
--------------
src/backend/commands/subscriptioncmds.c  |  8 +++++---
src/backend/replication/logical/worker.c |  7 +++++++
src/test/subscription/t/100_bugs.pl      | 30 ++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2025-08-19 06:00 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-08-19 06:00 pgsql: Fix self-deadlock during DROP SUBSCRIPTION. Amit Kapila <akapila@postgresql.org>
2025-08-19 06:00 pgsql: Fix self-deadlock during DROP SUBSCRIPTION. Amit Kapila <akapila@postgresql.org>
2025-08-19 06:00 pgsql: Fix self-deadlock during DROP SUBSCRIPTION. Amit Kapila <akapila@postgresql.org>
2025-08-19 06:00 pgsql: Fix self-deadlock during DROP SUBSCRIPTION. Amit Kapila <akapila@postgresql.org>
2025-08-19 06:00 pgsql: Fix self-deadlock during DROP SUBSCRIPTION. Amit Kapila <akapila@postgresql.org>
2025-08-19 06:00 pgsql: Fix self-deadlock during DROP SUBSCRIPTION. Amit Kapila <akapila@postgresql.org>
2025-08-19 06:00 pgsql: Fix self-deadlock during DROP SUBSCRIPTION. Amit Kapila <akapila@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox