Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXwXf-0005f9-PP for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Nov 2019 00:11:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXwXe-0005Kp-8O for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Nov 2019 00:11:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXwXd-0005IU-Sx for pgsql-bugs@lists.postgresql.org; Fri, 22 Nov 2019 00:11:18 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iXwXa-0000Q6-Ho for pgsql-bugs@lists.postgresql.org; Fri, 22 Nov 2019 00:11:16 +0000 Received: by mail-wr1-x42b.google.com with SMTP id z7so3146585wrl.13 for ; Thu, 21 Nov 2019 16:11:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=THDkVjgagA0FzPzsdbMOzmrbmmVyZ6497wuSJD0fApk=; b=Vugi5x3BIAxiS5I3jmJhpDY8GGfFG3RUPcMpFAGEB05N1OFKMjn/QyoC5CI046k8Cs WI0qPa7YFMQgg2Q+zHsIKEhoX+I8f4n3Rbyql2wi0wooTnQxlETabJZgese50WN+rc5C qrV9AnS5YBdu3uHOK0U617nALYS7IsyemGQCs8qPxXc6sHhAbufoLGJeBp66HJcqw623 pg+DuVZkgvit39B1WQZkVCfdgCXCdRn5Q8fDecRMK9ilVp+Z2xccwu4VqvJXcNQAZbYd R80T5+TXnAJ5gQPJ+U9wKDFAbWTIC9Ma9tlOp4WnUaH9YqdL2mINMuLUd/AWwJWRUKZm EhOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=THDkVjgagA0FzPzsdbMOzmrbmmVyZ6497wuSJD0fApk=; b=OGqCJZH+2th9Uf2oOBYgkxcLmnh1y1aaT4piftUDRxhYQpLuLBGlGIXGbkMjFMOegG YrvTZKTzf2Bdq6okTo2zEYDfb9Kepf5piaGwyhesUdDI7aMb6aCXRDw07ZOK7Ihxu6cx g2UlHWhU29q8WqufuuUMjHPQvM/VyXbG6oxJHx0utePoKOb0l1CzM2wmA87h4CwCz79t HEjRLU8EAgbBhJHeArxyYW/ZAMLdF7mfxkMGRGTPNPeKPVj86Uf+x0NbkqeJQQ79oLUS FsBdKt9kOEx1RQWpoEVfoJNmp/gLbXCsvfwhYvsK13gPshS5+LMv07kubMAp8MDnOOo3 x6tQ== X-Gm-Message-State: APjAAAUUx409LZLqj1sQaltr8X+hfRN97NwCTtasazuH65d+ZU4CTj+t OHsed3D6fGmJcJs9/nst2cSQog== X-Google-Smtp-Source: APXvYqxIE04huh+Bm8tyxEv0wpQEh2o+nmEL1xzJl0PPigMD7iya44bllXls7SO7fABTwJ569JqMaQ== X-Received: by 2002:adf:e94e:: with SMTP id m14mr14724842wrn.233.1574381472579; Thu, 21 Nov 2019 16:11:12 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id c11sm5029162wrv.92.2019.11.21.16.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 16:11:11 -0800 (PST) Date: Fri, 22 Nov 2019 01:11:10 +0100 From: Tomas Vondra To: Tom Lane Cc: =?utf-8?Q?Ond=C5=99ej?= Jirman , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16129: Segfault in tts_virtual_materialize in logical replication worker Message-ID: <20191122001110.zfv45fkjiwkmli6s@development> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <14166.1574380607@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Nov 21, 2019 at 06:56:47PM -0500, Tom Lane wrote: >Tomas Vondra 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