Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZQEiR-0001qB-Gw for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Aug 2015 13:08:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZQEiR-00065k-0s for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Aug 2015 13:08:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZQEiQ-00065Z-GF for pgsql-bugs@postgresql.org; Fri, 14 Aug 2015 13:08:10 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZQEiJ-0007lq-G9 for pgsql-bugs@postgresql.org; Fri, 14 Aug 2015 13:08:09 +0000 Received: by wicne3 with SMTP id ne3so17764155wic.0 for ; Fri, 14 Aug 2015 06:08:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=ClcgUg98vqAUd0RfEjRjcQIsazceP0r+ZDp3mwf8wbA=; b=HqpwXgCMSSzJO3PWjGTSm4J0ubPUVmKVF5DbiHtrJnH3uCn6u+W/vBCNXgH1rhMLAY bXq7c4scJoZYDfiAZbB+OPHfbNIB/hMkj1SWUDiZ8GFkho7kB0khLIf4B50v46FjTXPm zcz4Wa7jvWrMbZdJKkEJy7MQpCdpXjYoD0pwo506pxWkvE9dsn7oiQ68F6YVmj8IUhd+ J+8TyBfgFPzM3WTfRCzkAGuzyTIfXfRMsO66kZnB+a7cgRTxQSl8/wowWV5Pvw4T9Inh tkVPj7Q9qFLAR/06cHetrkftVqwYS4im1VP3Q+2JQb7V6Ywg//eHpmQa46cVpYVMqPeL lPhw== X-Gm-Message-State: ALoCoQl3eeyBr/x7wP4hVdRgOmkt0qBB8c2p7U+atcJdKEf9ttwCmzfhB1tNebovKxwi4wjdzVYm X-Received: by 10.180.80.70 with SMTP id p6mr6796550wix.43.1439557682265; Fri, 14 Aug 2015 06:08:02 -0700 (PDT) Received: from ashulgin01.corp.ad.zalando.net ([94.135.236.132]) by smtp.googlemail.com with ESMTPSA id m4sm8137163wjb.37.2015.08.14.06.08.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Aug 2015 06:08:01 -0700 (PDT) From: Oleksandr Shulgin To: feikesteenbergen@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13571: sql-only extension segfaults backend during creation References: <20150814125450.1670.49992@wrigleys.postgresql.org> Date: Fri, 14 Aug 2015 15:08:01 +0200 In-Reply-To: <20150814125450.1670.49992@wrigleys.postgresql.org> (feikesteenbergen@gmail.com's message of "Fri, 14 Aug 2015 12:54:50 +0000") Message-ID: <87k2sy6mry.fsf@ashulgin01.corp.ad.zalando.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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