pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ondřej Jirman <ienieghapheoghaiwida@xff.cz>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16129: Segfault in tts_virtual_materialize in logical replication worker
Date: Fri, 22 Nov 2019 01:11:10 +0100
Message-ID: <20191122001110.zfv45fkjiwkmli6s@development> (raw)
In-Reply-To: <14166.1574380607@sss.pgh.pa.us>
References: <20191121155707.pqkgjphh65o5fapz@core.my.home>
	<20191121161502.xfiy65i3cm6adscr@core.my.home>
	<20191121165752.dffge6bh756xlfdg@development>
	<20191121173555.midj6vp4dmiiqs24@core.my.home>
	<20191121185844.6qsqhwzzuhu3fpsg@core.my.home>
	<20191121214115.3tgefmvkmrzaim74@development>
	<20191121220854.ebdzjtloel56sfwu@development>
	<13122.1574375845@sss.pgh.pa.us>
	<20191121234701.2wtyc77zd5ux3myf@development>
	<14166.1574380607@sss.pgh.pa.us>

On Thu, Nov 21, 2019 at 06:56:47PM -0500, Tom Lane wrote:
>Tomas Vondra <tomas.vondra@2ndquadrant.com> writes:
>> On Thu, Nov 21, 2019 at 05:37:25PM -0500, Tom Lane wrote:
>> I don't think that's quite true. After the ExecCopySlot call, the
>> pass-by-ref Datums in remoteslot will point to a tuple attached to
>> localslot. But it does not pass the tuple 'ownership' to the remoteslot,
>> i.e. the flag TTS_FLAG_SHOULDFREE won't be set, i.e. the tuple won't be
>> freed.
>
>Nope:
>
>static void
>tts_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
>{
>	HeapTuple	tuple;
>	MemoryContext oldcontext;
>
>	oldcontext = MemoryContextSwitchTo(dstslot->tts_mcxt);
>	tuple = ExecCopySlotHeapTuple(srcslot);
>	MemoryContextSwitchTo(oldcontext);
>
>	ExecStoreHeapTuple(tuple, dstslot, true);
>}
>
>"remoteslot" will contain its very own copy of the data, which
>is then summarily freed by ExecClearSlot.
>

But remoteslot is virtual, so it calls tts_virtual_copyslot, not the
heap one. And AFAIK tts_virtual_copyslot only copies contents of the
tts_values/tts_isnull arrays.

>>> I imagine the only reason this code has gotten past the valgrind
>>> animals is that we're not testing cases where non-replaced columns
>>> in the subscriber table are of pass-by-ref types.
>
>> I haven't checked, but I'd imagine we actually do such tests. I've
>> however tried to reproduce this, unsuccessfully.
>
>I did check, and we don't.  See patch.
>
>It's possible that the OP is seeing some different problem,
>but I can definitely demonstrate that there is a problem
>that this change fixes.
>

Hmm. Will check.

regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services 





view thread (40+ messages)  latest in thread

Message-ID: <20191122001110.zfv45fkjiwkmli6s@development>
Permalink:  ../20191122001110.zfv45fkjiwkmli6s@development/
Also on:    postgresql.org/message-id/20191122001110.zfv45fkjiwkmli6s@development

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com, tgl@sss.pgh.pa.us, ienieghapheoghaiwida@xff.cz, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16129: Segfault in tts_virtual_materialize in logical replication worker
  In-Reply-To: <20191122001110.zfv45fkjiwkmli6s@development>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox