pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: memory leak in trigger handling (since PG12)
Date: Wed, 24 May 2023 19:45:34 +0200
Message-ID: <9ed6f2b5-0c5e-e708-2c7f-3581c4b80ed6@enterprisedb.com> (raw)
In-Reply-To: <1137299.1684942630@sss.pgh.pa.us>
References: <222a3442-7f7d-246c-ed9b-a76209d19239@enterprisedb.com>
	<1137299.1684942630@sss.pgh.pa.us>



On 5/24/23 17:37, Tom Lane wrote:
> Tomas Vondra <tomas.vondra@enterprisedb.com> writes:
>> While looking for other places allocating stuff in ExecutorState (for
>> the UPDATE case) and leaving it there, I found two more cases:
> 
>> 1) copy_plpgsql_datums
> 
>> 2) make_expanded_record_from_tupdesc
>>    make_expanded_record_from_exprecord
> 
>> All of this is calls from plpgsql_exec_trigger.
> 
> Can you show a test case in which this happens?  I added some
> instrumentation and verified at least within our regression tests,
> copy_plpgsql_datums' CurrentMemoryContext is always plpgsql's
> "SPI Proc" context, so I do not see how there can be a query-lifespan
> leak there, nor how your 0003 would fix it if there is.
> 

Interesting. I tried to reproduce it, but without success, and it passes
even with an assert on the context name. The only explanation I have is
that the gdb script I used might have been a bit broken - it used
conditional breakpoints like this one:

  break AllocSetAlloc if strcmp(((MemoryContext) $rdi)->name, \
                                "ExecutorState") == 0
  commands
  bt
  cont
  end

but I just noticed gdb sometimes complains about this:

  Error in testing breakpoint condition:
  '__strcmp_avx2' has unknown return type; cast the call to its declared
  return type

The breakpoint still fires all the commands, which is pretty surprising
behavior, but that might explain why I saw copy_plpgsql_data as another
culprit. And I suspect the make_expanded_record calls might be caused by
the same thing.

I'll check deeper tomorrow, when I get access to the original script
etc. We can ignore these cases until then.

Sorry for the confusion :-/


regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company





view thread (32+ messages)  latest in thread

Message-ID: <9ed6f2b5-0c5e-e708-2c7f-3581c4b80ed6@enterprisedb.com>
Permalink:  ../9ed6f2b5-0c5e-e708-2c7f-3581c4b80ed6@enterprisedb.com/
Also on:    postgresql.org/message-id/9ed6f2b5-0c5e-e708-2c7f-3581c4b80ed6@enterprisedb.com

 · 

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-hackers@postgresql.org
  Cc: tomas.vondra@enterprisedb.com, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org
  Subject: Re: memory leak in trigger handling (since PG12)
  In-Reply-To: <9ed6f2b5-0c5e-e708-2c7f-3581c4b80ed6@enterprisedb.com>

* 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