Thread: BUG #6249: Segmentation fault in VirtualXactLock()

BUG #6249: Segmentation fault in VirtualXactLock()

From
"Fujii Masao"
Date:
The following bug has been logged online:

Bug reference:      6249
Logged by:          Fujii Masao
Email address:      masao.fujii@gmail.com
PostgreSQL version: 9.2dev
Operating system:   Linux hermes 2.6.38-11-generic #50-Ubuntu SMP Mon Sep 12
21:18:14 UTC 2011 i686 i686 i386 GNU/Linux
Description:        Segmentation fault in VirtualXactLock()
Details:

When I built Streaming Replication and Hot Standby environment, set
max_standby_streaming_delay to 1s and ran the following shell script which
creates the conflict between read-only query and recovery, SEGV occurred on
the standby.

----------------------
#!/bin/sh

# Master's port: 5432
# Standby's port: 9999

psql -c "CREATE TABLE tbl (id int)" -p 5432
psql -c "INSERT INTO tbl VALUES(1)" -p 5432

sleep 1

psql -c "SELECT pg_sleep(60) FROM tbl" -p 9999 &

sleep 1

psql -c "DELETE FROM tbl" -p 5432
psql -c "VACUUM tbl" -p 5432
----------------------

backtrace is:
Core was generated by `postgres: startup process   recovering 000000'.
Program terminated with signal 11, Segmentation fault.
#0  0x083114db in VirtualXactLock ()
(gdb) bt
#0  0x083114db in VirtualXactLock ()
#1  0x083072d1 in ResolveRecoveryConflictWithVirtualXIDs ()
#2  0x08307355 in ResolveRecoveryConflictWithSnapshot ()
#3  0x080b8abc in heap_xlog_clean ()
#4  0x080bc31a in heap2_redo ()
#5  0x080f02fd in StartupXLOG ()
#6  0x080f6c70 in StartupProcessMain ()
#7  0x0811d5f9 in AuxiliaryProcessMain ()
#8  0x082d17e4 in StartChildProcess ()
#9  0x082cd151 in PostmasterMain ()
#10 0x0824d6b4 in main ()

I was not able to reproduce this issue on 9.1.1. So the bug would exist only
on 9.2dev.

Re: BUG #6249: Segmentation fault in VirtualXactLock()

From
Fujii Masao
Date:
On Tue, Oct 11, 2011 at 10:44 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
> When I built Streaming Replication and Hot Standby environment, set
> max_standby_streaming_delay to 1s and ran the following shell script which
> creates the conflict between read-only query and recovery, SEGV occurred on
> the standby.

In my investigation, the cause is that VirtualXactLock() doesn't
handle correctly
the case where BackendIdGetProc() returns NULL when the target backend has
already ended. Attached patch will fix this issue.

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachment

Re: BUG #6249: Segmentation fault in VirtualXactLock()

From
Robert Haas
Date:
On Tue, Oct 11, 2011 at 3:14 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
> On Tue, Oct 11, 2011 at 10:44 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
>> When I built Streaming Replication and Hot Standby environment, set
>> max_standby_streaming_delay to 1s and ran the following shell script which
>> creates the conflict between read-only query and recovery, SEGV occurred on
>> the standby.
>
> In my investigation, the cause is that VirtualXactLock() doesn't
> handle correctly
> the case where BackendIdGetProc() returns NULL when the target backend has
> already ended. Attached patch will fix this issue.

Thanks, committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company