Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi, On Mon, Aug 24, 2026 at 5:01 AM vignesh C wrote: > > I found an issue in GetSubscriptionRelations() when a REFRESH > PUBLICATION is executed while a subscribed relation is dropped > concurrently. Thanks for reporting and sending the patch. > GetSubscriptionRelations() scans pg_subscription_rel using the catalog > snapshot taken when the scan starts, and then looks up the relation's > relkind through the syscache. If the relation is dropped and the drop > commits, the pg_subscription_rel row can still be visible while the > corresponding pg_class row is already gone. In this case, > get_rel_relkind() returns '\0'. > > This can be reproduced with the following steps: > I have reproduced it through debugger: > > get_rel_relkind will return '\0' which causes the assertion failure at: > .... > relkind = get_rel_relkind(subrel->srrelid); > > Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION || > relkind == RELKIND_PARTITIONED_TABLE); How easy is it to hit this with direct SQL without a debugger or injection point? In production builds (no assertions), what happens when the relation is concurrently dropped? Does the logical replication worker error or crash, and if it exits, does it recover in the next cycle since the relation won't be in the list anymore? If it's not easily reproducible with direct SQL, I don't think we need to fix this at all, because none of the other places (for example, getOwnedSequences_internal() or GetPubPartitionOptionRelations()) handle a null relkind either. Even if we were to fix, I would just remove the assertion and continue in the loop if the relation is not what we expect. Would that work? -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Re: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
Hi, On Mon, Aug 24, 2026 at 9:52 PM Amit Kapila wrote: > > On Mon, Aug 24, 2026 at 11:35 PM Bharath Rupireddy > wrote: > > > > If it's not easily reproducible with direct SQL, I don't think we need > > to fix this at all, because none of the other places (for example, > > getOwnedSequences_internal() or GetPubPartitionOptionRelations()) > > handle a null relkind either. > > But they will work (as they are if checks) and as far as I can see > they will do the right thing which means they will tolerate concurrent > drops but if not I feel it is better to fix those as well. Yes, it's worth exploring all of these in the logical replication code (maybe separately though). > > Even if we were to fix, I would just > > remove the assertion and continue in the loop if the relation is not > > what we expect. Would that work? > > As we are scanning pg_susbcription_rel unexpected relkind here (not > '\0', something else entirely) would probably indicate a real bug > worth surfacing, not silently swallowing. So, I suggest we can remove > assert after Vignesh's fix and have an elog(ERROR, "unexpected > relkind: %d", (int) relkind);. We use such an elog at other places as > well. Works for me, and I think both can go in one patch. After the relkind fix, replacing the assertion with an error means that in the rare scenario where the OID of the dropped table gets reused to create a relation that's not expected, we catch it. I'm all in favor of tightening this anyway. On backpatching this fix, I think HEAD and PG19 (still in beta) are enough, because it's not easily reproducible with direct SQL. For the same reason, I'm fine with not having an injection point and a TAP test for this. -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
RE: Assertion failure in GetSubscriptionRelations() with concurrent DROP TABLE
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Vignesh, Thanks for updating the patch. I confirmed it could fix the issue. ``` + else + elog(ERROR, "unexpected relkind: %d", (int) relkind); ``` I feel \"%c\" might be better than %d, like what ProcessUtilitySlow() does, because the relkind is defined as char. Best regards, Hayato Kuroda FUJITSU LIMITED