Re: BUG #17792: MERGE uses uninitialized pointer and crashes when target tuple is updated concurrently - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: BUG #17792: MERGE uses uninitialized pointer and crashes when target tuple is updated concurrently
Date
Msg-id 20230214112933.cshqgnzpcioedizy@alvherre.pgsql
Whole thread Raw
In response to BUG #17792: MERGE uses uninitialized pointer and crashes when target tuple is updated concurrently  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #17792: MERGE uses uninitialized pointer and crashes when target tuple is updated concurrently  (Alexander Lakhin <exclusion@gmail.com>)
Re: BUG #17792: MERGE uses uninitialized pointer and crashes when target tuple is updated concurrently  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List 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

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #17793: Query with large number of joins crashes PostgreSQL
Next
From: Francisco Olarte
Date:
Subject: Re: BUG #17793: Query with large number of joins crashes PostgreSQL