Re: SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues
Date
Msg-id 20061212123233.GA12721@alvh.no-ip.org
Whole thread Raw
In response to SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues  ("J. Greg Davidson" <jgd@well.com>)
Responses Re: SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
J. Greg Davidson wrote:
> I have a user defined type implemented in C and SPI which has been
> crashing a lot.  I found a small enough case to trace the whole thing
> with gdb and found that while connected to SPI I was doing a get_value
> on a type T implemented in C and SPI.  SPI_getvalue led to a call to T's
> output routine which called SPI_connect which failed because the
> previous SPI connection was still in force. The whole transaction was
> aborted, so without a long gdb session I wouldn't have caught it.
> Ironically the call to SPI_getvalue was in my debugging code!

The question that jumps at me is why are you using SPI inside a type's
output function?  You should really avoid doing that.

If you absolutely need to do it, enclosing the function in SPI_push/pop
seems to me the least bad answer.

pgsql-bugs by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: 8.2 pl/pgsql crash bug (WAS: [pgadmin-support] Error craches
Next
From: ""
Date:
Subject: BUG #2824: Problem with installation by Remote Desktop