PosgreSQL backend process crashed with signal 9

From: Aleksey Romanov <drednout(dot)by(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: PosgreSQL backend process crashed with signal 9
Date: 2016-04-05 12:19:43
Message-ID: CAMoxhtvmRsSs7QaTP4+Uq2DjJP+Sgc=hSx7Z6gyreSrqiwXi-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

In case of simultaneous calling plpythonu stored procedure and locking test
table I have reproducible segfault of PosgreSQL backend process.

Steps to reproduce:
0) initialize database schema and data:
$ psql -h localhost -p 5434 -U test < init_schema.sql
$ cat init_schema.sql
DROP TABLE IF EXISTS test;
CREATE TABLE IF NOT EXISTS test
(
id BIGSERIAL PRIMARY KEY,
amount BIGINT,
counter BIGINT DEFAULT 0
);
CREATE INDEX ON test (counter) where counter > 0;
INSERT INTO test (amount) VALUES (1);
INSERT INTO test (amount) VALUES (2);
INSERT INTO test (amount) VALUES (3);
INSERT INTO test (amount) VALUES (4);
INSERT INTO test (amount) VALUES (5);

CREATE OR REPLACE FUNCTION test_plpy_postgres_crash(record_id INTEGER)
RETURNS boolean
AS $$
select_query = """
SELECT * FROM test WHERE id = $1
"""
if "select_plan" in GD:
select_plan = GD["select_plan"]
else:
select_plan = plpy.prepare(select_query, ["integer"])
GD["select_plan"] = select_plan

select_cursor = plpy.cursor(select_plan, [record_id])
return True
$$ LANGUAGE plpythonu;

1) open 2 psql client sessions to PosgreSQL 9.5.2:
$ psql -h localhost -p 5434 -U test
$ psql -h localhost -p 5434 -U test

2) enter the following statement in the one of client sessions:
test=# select pg_sleep(1) ; begin; lock test ; select sum(counter) from
test ; select pg_sleep(60);
pg_sleep
----------

(1 row)

BEGIN
LOCK TABLE
sum
-----
0
(1 row)

3) after successful taking table lock enter the following statement in the
second client session:
test=# SELECT test_plpy_postgres_crash(trunc(random() * 5 + 1)::integer);

4) wait several seconds and press CTRL+C in the second client session
5) PosgreSQL backend process crass is occurred:
test=# select pg_sleep(1) ; begin; lock test ; select sum(counter) from
test ; select pg_sleep(60);
pg_sleep
----------

(1 row)

BEGIN
LOCK TABLE
sum
-----
0
(1 row)

WARNING: terminating connection because of crash of another server process
DETAIL: The postmaster has commanded this server process to roll back the
current transaction and exit, because another server process exited
abnormally and possibly corrupted shared memory.
HINT: In a moment you should be able to reconnect to the database and
repeat your command.
SSL SYSCALL error: EOF detected
The connection to the server was lost. Attempting reset: Failed.

test=# SELECT test_plpy_postgres_crash(trunc(random() * 5 + 1)::integer);
^CCancel request sent
SSL SYSCALL error: EOF detected
The connection to the server was lost. Attempting reset: Failed.

Dmesg log:
$ dmesg| tail
[1904728.889471] postgres[21138]: segfault at fffffffffffffff0 ip
00007f25462c7724 sp 00007fff96c155a0 error 5 in
postgres[7f2545eb9000+5f1000]

PosgreSQL version:
test=# select version();
version

-------------------------------------------------------------------------------------------------
PostgreSQL 9.5.2 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu
4.8.2-19ubuntu1) 4.8.2, 64-bit
(1 row)

System info:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
$ uname -a
Linux aromanov 3.13.0-79-generic #123-Ubuntu SMP Fri Feb 19 14:27:58 UTC
2016 x86_64 x86_64 x86_64 GNU/Linux

--
Best regards,
Aleksey Romanov
Web Developer, Wargaming.net

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2016-04-05 19:29:28 Re: PosgreSQL backend process crashed with signal 9
Previous Message bert.vanhertum.ext 2016-04-05 08:35:22 BUG #14065: Dutch_Belgium locale not working correctly