Fix the check to limit sync workers.
authorAmit Kapila <[email protected]>
Tue, 19 Apr 2022 03:19:49 +0000 (08:49 +0530)
committerAmit Kapila <[email protected]>
Tue, 19 Apr 2022 03:19:49 +0000 (08:49 +0530)
We don't allow to invoke more sync workers once we have reached the sync
worker limit per subscription. But the check to enforce this also doesn't
allow to launch an apply worker if it gets restarted.

This code was introduced by commit de43897122 but we caught the problem
only with the test added by recent commit c91f71b9dc which started failing
occasionally in the buildfarm.

As per buildfarm.
Diagnosed-by: Amit Kapila, Masahiko Sawada, Tomas Vondra
Author: Amit Kapila
Backpatch-through: 10
Discussion: https://postgr.es/m/CAH2L28vddB_NFdRVpuyRBJEBWjz4BSyTB=_ektNRH8NJ1jf95g@mail.gmail.com
    https://postgr.es/m/f90d2b03-4462-ce95-a524-d91464e797c8@enterprisedb.com

src/backend/replication/logical/launcher.c

index 6f25b2c2ad5c6be9e8acda0c2430c4ea7e5a29c2..0adb2d1d665539d4710393ae9c0505c7ce94300c 100644 (file)
@@ -344,11 +344,11 @@ retry:
        }
 
        /*
-        * If we reached the sync worker limit per subscription, just exit
-        * silently as we might get here because of an otherwise harmless race
-        * condition.
+        * We don't allow to invoke more sync workers once we have reached the sync
+        * worker limit per subscription. So, just return silently as we might get
+        * here because of an otherwise harmless race condition.
         */
-       if (nsyncworkers >= max_sync_workers_per_subscription)
+       if (OidIsValid(relid) && nsyncworkers >= max_sync_workers_per_subscription)
        {
                LWLockRelease(LogicalRepWorkerLock);
                return;