Re: BUG #17607: Server process crashes when PLpgSQL function raises error in subtransaction
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: thomas.d.mckay@gmail.com
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>, pgsql-bugs@lists.postgresql.org
Date: 2022-09-25T18:24:07Z
Lists: pgsql-bugs
Attachments
- fix-trigger-tupdesc-refcount-issue.patch (text/x-diff) patch
I wrote: > PG Bug reporting form <noreply@postgresql.org> writes: >> I've encountered a bug while doing some SQL migrations on a PostgreSQL 13.8 >> server. My initial use-case is a Django app running migrations, a test setup >> and a test, but that code was more than 10K lines of DDL, so I've reduced >> the code to a minimal reproducible example (as best I could). > Thanks for the minimal reproducer! I confirm that this problem is visible > in the v12 and v13 branches, but not before or after. I got a chance to look at this today, and what I find is that we're making a tuple slot that will be freed at end of subtransaction, but it has a refcount on a refcounted tuple descriptor that belongs to the Portal's resowner. While trying to free the slot, we get a complaint because the subtransaction's resowner isn't holding the appropriate tupdesc reference. It seems to me there are probably other hazards here, because the tupdesc could possibly also go away before the slot does. I think what we ought to do is copy the tupdesc, so that we have a non-refcounted descriptor that we know has exactly the right lifespan. As attached. Not sure about whether to bother with a test case. The submitted reproducer doesn't work in >= v14, and even in v12/v13 it seems awfully corner-case-ish. (I find for instance that you need the ALTER TABLE step rather than just making the table in one step, and I'm a tad baffled as to why.) In any case, I've got zero faith that there are not other ways to trigger the same problem, so I think we need to apply this up to HEAD. regards, tom lane
Commits
-
Fix tupdesc lifespan bug with AfterTriggersTableData.storeslot.
- c82766c0298a 15.0 landed
- 9923764614a0 14.6 landed
- 8c17c8615470 13.9 landed
- 51976309450c 12.13 landed
- 216f9c1ab3a4 16.0 landed