Re: BUG #17792: MERGE uses uninitialized pointer and crashes when target tuple is updated concurrently

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17792: MERGE uses uninitialized pointer and crashes when target tuple is updated concurrently
Date: 2023-02-14 11:29:33
Message-ID: 20230214112933.cshqgnzpcioedizy@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2023-Feb-14, PG Bug reporting form wrote:

> When executing the following queries with valgrind:
> echo "
> CREATE TABLE source (sid integer);
> INSERT INTO source VALUES (1);
> CREATE TABLE target (tid integer, tval integer);
> INSERT INTO target VALUES (1, 1);
> " | psql

> At nodeModifyTable.c:2992 I see:
> if (!TupIsNull(context->cpUpdateRetrySlot))
>
> It looks like cpUpdateRetrySlot was not initialized on the context creation
> in ExecModifyTable(), and ExecCrossPartitionUpdate(), where it could get a
> value, just not called for this case.

Hmm, yeah: because this is not a partitioned table, we are definitely
not expecting that cpUpdateRetrySlot will be set. Can you still
reproduce the problem with the attached patch?

I'm not sure that the location of the initialization is best. My first
impulse was to add it in line 3618, with the "Set global context" lines;
but then I think it's possible for one tuple of a partition to be routed
correctly and a later one that is concurrently updated suffer from an
improper value in cpUpdateRetrySlot.

Also, the comment is not great ...

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/

Attachment Content-Type Size
merge-uninit.patch text/x-diff 580 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Francisco Olarte 2023-02-14 11:51:02 Re: BUG #17793: Query with large number of joins crashes PostgreSQL
Previous Message PG Bug reporting form 2023-02-14 09:33:23 BUG #17793: Query with large number of joins crashes PostgreSQL