pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oleksandr Shulgin <oleksandr.shulgin@zalando.de>
To: feikesteenbergen@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13571: sql-only extension segfaults backend during creation
Date: Fri, 14 Aug 2015 15:08:01 +0200
Message-ID: <87k2sy6mry.fsf@ashulgin01.corp.ad.zalando.net> (raw)
In-Reply-To: <20150814125450.1670.49992@wrigleys.postgresql.org>
References: <20150814125450.1670.49992@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

feikesteenbergen@gmail.com writes:

> The following bug has been logged on the website:
>
> Bug reference:      13571
> Logged by:          Feike Steenbergen
> Email address:      feikesteenbergen@gmail.com
> PostgreSQL version: 9.5alpha2
> Operating system:   Debian jessie x86_64
> Description:        
>
> When installing a sql-only extension, my backend crashes taking the cluster
> with it.
>
> After some debugging we have created a reproducable testcase.
>
> postgres@postgres=# create extension castbug;
> server closed the connection unexpectedly
>
> castbug.control:
>
> relocatable = false
> superuser   = true
> comment 	= 'This triggers a segfault on 9.5alpha2'
> default_version = unstable
>
> castbug--unstable.sql:
>
> DO
> $$
> DECLARE
>     roles text[] := '{"job_scheduler","job_monitor"}';
> BEGIN
> END;
> $$;
>
> SELECT count(*)
>   FROM pg_class
> CROSS JOIN generate_series(1,100);
>
> DO
> $$
> DECLARE
>     something text[] := '{"jb_scheduler","job_monitr"}';
> BEGIN
> END;
> $$;

I did a quick debugging session on this and I believe that the cast_hash
logic in pl_exec.c is to blame.

The first time get_cast_hashentry() tries to find a cast, it creates the
global hash table and inserts an entry for the cast in it, using the
current memory context, which is of the first DO block.  When the first
DO block ends, the memory context is freed, but the cast_hash with all
its content stays.  So the next time we're trying to find an appropriate
cast function in the second DO block, we are getting the old one, but it
is now pointing to the deallocated memory.

I'm not sure what would be the proper fix for this.

--
Alex


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (6+ messages)  latest in thread

Message-ID: <87k2sy6mry.fsf@ashulgin01.corp.ad.zalando.net>
Permalink:  ../87k2sy6mry.fsf@ashulgin01.corp.ad.zalando.net/
Also on:    postgresql.org/message-id/87k2sy6mry.fsf@ashulgin01.corp.ad.zalando.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: oleksandr.shulgin@zalando.de, feikesteenbergen@gmail.com
  Subject: Re: BUG #13571: sql-only extension segfaults backend during creation
  In-Reply-To: <87k2sy6mry.fsf@ashulgin01.corp.ad.zalando.net>
  References: <20150814125450.1670.49992@wrigleys.postgresql.org> <87k2sy6mry.fsf@ashulgin01.corp.ad.zalando.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox