pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Maxim Boguk <maxim.boguk@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5798: Some weird error with pl/pgsql procedure
Date: Mon, 21 Feb 2011 19:31:00 -0500
Message-ID: <9875.1298334660@sss.pgh.pa.us> (raw)
In-Reply-To: <26057.1298311836@sss.pgh.pa.us>
References: <201012210248.oBL2m9sp090535@wwwmaster.postgresql.org>
	<AANLkTinq4ET1h3n7RznWVDTmMQBzBNnp=GvM=2zKDxa+@mail.gmail.com>
	<AANLkTi==2o9JPJwwfOsL2CnFpcw1YYy_AY_qCiKtg05W@mail.gmail.com>
	<AANLkTinzR3KOumGE_FBiBu8PWU=33guLrZW78qC+2KrV@mail.gmail.com>
	<AANLkTinvd10Qxzmnhn4881kZfqacZ4WpW2Vvt-peY=A6@mail.gmail.com>
	<28329.1298131693@sss.pgh.pa.us>
	<AANLkTimQ1qCbiUZJcA8h9BSFHvqaxygTk+nSV-i09s1p@mail.gmail.com>
	<AANLkTi=MLmN9pwmXat=GtrnwmNKixy_a8kFXDJY5BhRW@mail.gmail.com>
	<10910.1298236066@sss.pgh.pa.us>
	<AANLkTi=H3wOXQ+vx7mJEVkw5o=GcRiLbyTWBmUKLwb0b@mail.gmail.com>
	<26057.1298311836@sss.pgh.pa.us>

I wrote:
> Ugh.  That quick little "ExecRemoveJunk" is a lot more dangerous than it
> looks.  I had actually looked at this before, but concluded it was OK
> because I couldn't reproduce the problem with a trigger in place.
> I guess I wasn't unlucky enough to have the chance pointer equality
> occur.

On closer inspection, the palloc collision is actually extremely likely,
because what will happen is we'll pfree the old tuple and immediately
palloc the new one, and if the new one is of sufficiently similar size
that it needs the same size of alloc chunk, it's *guaranteed* to get
that same chunk back, because of the LIFO free-chunk chains in aset.c.

The reason that the problem is hard to reproduce is that most triggers
(certainly those written in plpgsql) will give back newly allocated
tuples even when you return the unmodified NEW tuple.  The only way to
expose the problem is for ExecBRUpdateTrigger's trigger-calling loop to
not replace the "newtuple", and the easiest way for that to happen is if
all the triggers are disabled.  So that's why you're seeing it when
fooling with the replication-role setting.  I was able to reproduce the
failure by creating a trigger with a false WHEN condition, and of course
there are other ways to prevent a trigger from being called too.

			regards, tom lane



view thread (17+ messages)  latest in thread

Message-ID: <9875.1298334660@sss.pgh.pa.us>
Permalink:  ../9875.1298334660@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9875.1298334660@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, maxim.boguk@gmail.com, robertmhaas@gmail.com
  Subject: Re: BUG #5798: Some weird error with pl/pgsql procedure
  In-Reply-To: <9875.1298334660@sss.pgh.pa.us>
  References: <201012210248.oBL2m9sp090535@wwwmaster.postgresql.org> <AANLkTinq4ET1h3n7RznWVDTmMQBzBNnp=GvM=2zKDxa+@mail.gmail.com> <AANLkTi==2o9JPJwwfOsL2CnFpcw1YYy_AY_qCiKtg05W@mail.gmail.com> <AANLkTinzR3KOumGE_FBiBu8PWU=33guLrZW78qC+2KrV@mail.gmail.com> <AANLkTinvd10Qxzmnhn4881kZfqacZ4WpW2Vvt-peY=A6@mail.gmail.com> <28329.1298131693@sss.pgh.pa.us> <AANLkTimQ1qCbiUZJcA8h9BSFHvqaxygTk+nSV-i09s1p@mail.gmail.com> <AANLkTi=MLmN9pwmXat=GtrnwmNKixy_a8kFXDJY5BhRW@mail.gmail.com> <10910.1298236066@sss.pgh.pa.us> <AANLkTi=H3wOXQ+vx7mJEVkw5o=GcRiLbyTWBmUKLwb0b@mail.gmail.com> <26057.1298311836@sss.pgh.pa.us> <9875.1298334660@sss.pgh.pa.us>

* 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