server crash: displaying sqlerrm in exception block

Started by Asif Aliabout 19 years ago6 messagesbugs
Jump to latest
#1Asif Ali
asifalirehman@gmail.com

PostgreSQL version: 8.2.1
Operating system: Fedora 3
Description: server crash
Details:

I have compiled postgres 8.2.1 with gcc 4.1. and when executed this function
it crashes the server.

i also fetched the code from postgres repository (8.3devel) and tested this
code but it still crashing server.

Steps to produce
----------------------

CREATE OR REPLACE FUNCTION func2() RETURNS int as $$
BEGIN
RAISE EXCEPTION 'ex -----';
EXCEPTION
WHEN OTHERS THEN
RAISE INFO 'sql error msg %',sqlerrm;
DECLARE
v_msg VARCHAR(200) := sqlerrm;
BEGIN
RAISE INFO 'sql error msg %',sqlerrm;
ENd;
RETURN 0;
END;
$$ LANGUAGE plpgsql;

select func2();

Output
---------
INFO: sql error msg ex -----
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Asif Ali (#1)
Re: server crash: displaying sqlerrm in exception block

"Asif Ali" <asifalirehman@gmail.com> writes:

I have compiled postgres 8.2.1 with gcc 4.1. and when executed this function
it crashes the server.

The attached patch (against HEAD) fixes your test case, but please see
whether it fixes your original problem; I'm not 100% confident in it
yet. There seem to be two different bugs here...

regards, tom lane

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Asif Ali (#1)
Re: server crash: displaying sqlerrm in exception block

"Asif Ali" <asifalirehman@gmail.com> writes:

your patch fixes the crash but instead of displaying the sqlerrm value, it
is displaying <NULL> in
pl block, declared inside exception block.

Hm, not what I see here. Could you submit a test case that does that?

regards, tom lane

#4Asif Ali
asifalirehman@gmail.com
In reply to: Tom Lane (#3)
Re: server crash: displaying sqlerrm in exception block

here is the test case

CREATE OR REPLACE FUNCTION func() RETURNS int as $$
BEGIN
RAISE EXCEPTION 'ex -----';
EXCEPTION
WHEN OTHERS THEN
RAISE INFO 'sql error msg %',sqlerrm;
DECLARE
v_msg VARCHAR(200) := sqlerrm;
BEGIN
RAISE INFO 'sql error msg %',sqlerrm; -- it show's <NULL>
RAISE INFO 'sql error v_msg %',v_msg; -- it show's <NULL>
ENd;
RETURN 0;
END;
$$ LANGUAGE plpgsql;

Regards,
--Asif

On 2/8/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:

"Asif Ali" <asifalirehman@gmail.com> writes:

your patch fixes the crash but instead of displaying the sqlerrm value,

it

is displaying <NULL> in
pl block, declared inside exception block.

Hm, not what I see here. Could you submit a test case that does that?

regards, tom lane

--
Regards,
--Asif Ali Rehman

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Asif Ali (#4)
Re: server crash: displaying sqlerrm in exception block

"Asif Ali" <asifalirehman@gmail.com> writes:

here is the test case

It works for me:

regression=# select func();
INFO: sql error msg ex -----
INFO: sql error msg ex -----
INFO: sql error v_msg ex -----
func
------
0
(1 row)

Are you sure you applied the patch correctly? In particular, you'd need
a working version of bison to rebuild the gram.y file --- the behavior
you're reporting sounds like what would happen if that hadn't gotten
rebuilt.

regards, tom lane

#6Asif Ali
asifalirehman@gmail.com
In reply to: Tom Lane (#5)
Re: server crash: displaying sqlerrm in exception block

Hi,
well i just updated the code and found your patch is applied in there and
it's working. may be i missed something while applying your patch.

Regards,
--Asif

On 2/8/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:

"Asif Ali" <asifalirehman@gmail.com> writes:

here is the test case

It works for me:

regression=# select func();
INFO: sql error msg ex -----
INFO: sql error msg ex -----
INFO: sql error v_msg ex -----
func
------
0
(1 row)

Are you sure you applied the patch correctly? In particular, you'd need
a working version of bison to rebuild the gram.y file --- the behavior
you're reporting sounds like what would happen if that hadn't gotten
rebuilt.

regards, tom lane

--
Regards,
--Asif Ali Rehman