pgsql-9.0.1-assertion-failure

Version:

9.0.1

Links:

Bug report: http://archives.postgresql.org/pgsql-hackers/2010-10/msg01737.php

Patch: http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=ef55e294e66725c412d55b9689328235141d816d

Symptom:

Crash. (Assertion failed).

Is there any log message?:

Yes.

How it is diagnosed:

Reproduced.

How to reproduce:

1. /posgres -D ../data (previously using ./initdb ../data)

2../psql mydb  (previously using createdb mydb to create database mydb )

3. # select * from pg_backend_pid();

15920

4.  gdb -p 15920

5.

mydb=# begin;

drop function if exists year(timestamp);

create or replace function year(timestamp)

returns int as $$

        select extract(year from $1)::int;

$$ language sql immutable;

drop function if exists segfault_setof(int);

create or replace function segfault_setof(int)

returns setof date as $$

        select s::date

        from generate_series(timestamp '2001-01-01', timestamp '2020-01-01', '1 day') s

        where year(s) <= $1 and year(s) >= $1;

$$ language sql stable;

select s from segfault_setof(year(current_date)::int) s;

rollback;

6.

TRAP: FailedAssertion("!(((list) == ((List *) ((void *)0)) ||

((((Node*)((list)))->type) == T_List)))", File: "list.c", Line: 130)

If I attach gdb to the server process, here's my backtrace as the

assert is fired:

#0  0x00007f0247f7f1b5 in raise () from /lib/libc.so.6

#1  0x00007f0247f805e0 in abort () from /lib/libc.so.6

#2  0x00000000006fbf6d in ExceptionalCondition (conditionName=<value

optimized out>,

    errorType=<value optimized out>, fileName=<value optimized out>,

    lineNumber=<value optimized out>) at assert.c:57

#3  0x00000000005acdbb in lappend (list=0xc49e60, datum=0xc562f0) at list.c:130

#4  0x00000000005e536f in record_plan_function_dependency 

(glob=0xb6bb78, funcid=16385)

    at setrefs.c:1738

#5  0x00000000005f378f in inline_set_returning_function

(root=0xb6c140, rte=0xb6bc10)

    at clauses.c:4318

#6  0x00000000005eaced in inline_set_returning_functions (root=0xb6c140)

    at prepjointree.c:438

Root cause:
Invalid memory access, protected by memory safe check (assertion).

#define IsPointerList(l)        ((l) == NIL || IsA((l), List))

pg_list.h 69

#define NIL ((List *) NULL)

 nodes.h 451

#define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)

    127 List *

    128 lappend(List *list, void *datum)

    129 {

    130     Assert(IsPointerList(list));

    131

    132     if (list == NIL)

    133         list = new_list(T_List);

    134     else

    135         new_tail_cell(list);

    136

    137     lfirst(list->tail) = datum;

    138     check_list_invariants(list);

    139     return list;

    140 }

void record_plan_function_dependency(PlannerGlobal *glob, Oid funcid)  {

        … ...

        glob->invalItems = lappend(glob->invalItems, inval_item);

}

Query * inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte) {

    … …

    +  /* copy up any new invalItems, too */

    +  root->glob->invalItems = list_concat(saveInvalItems,

    +          copyObject(root->glob->invalItems));

    MemoryContextDelete(mycxt);

    error_context_stack = sqlerrcontext.previous;

    ReleaseSysCache(func_tuple);

    /*

     * Since there is now no trace of the function in the plan tree, we must

     * explicitly record the plan's dependency on the function.

     */

    record_plan_function_dependency(root->glob, func_oid);

}

Pattern:

Failed memory safety check (assertion).

Can we automatically anticipate?

Yes. Log before abort.