dbTalk Databases Forums  

Re: [BUGS] SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Alvaro Herrera
 
Posts: n/a

Default Re: [BUGS] SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues - 12-12-2006 , 06:33 AM






J. Greg Davidson wrote:
Quote:
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.

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] SPI_getvalue calls output function w/o pushing existing SPI connection + 2 extra issues - 12-12-2006 , 10:51 AM






Alvaro Herrera <alvherre (AT) commandprompt (DOT) com> writes:
Quote:
The question that jumps at me is why are you using SPI inside a type's
output function? You should really avoid doing that.
Offhand it seems like it should work, but the real problem is that there
are probably a ton of code paths besides SPI_getvalue() that would need
to be changed to make it bulletproof. I don't have a big problem with
adding SPI_push/pop inside SPI_getvalue, but what else might need to
change?

Quote:
If you absolutely need to do it, enclosing the function in SPI_push/pop
seems to me the least bad answer.
That would be the Wrong Thing if the function could ever be called when
*not* connected to SPI, which of course is the normal case for a type
I/O function. Correct code would be something like

bool connected = false;

if (_SPI_curid + 1 == _SPI_connected) /* connected */
{
connected = true;
SPI_push();
}

... do it ...

if (connected)
SPI_pop();

and this is only possible inside spi.c because those variables aren't
exported.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.