Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aYzNF-0002SY-5b for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Feb 2016 17:06:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aYzNE-00085p-MF for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Feb 2016 17:06:44 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aYzNE-00085i-2K for pgsql-bugs@postgresql.org; Thu, 25 Feb 2016 17:06:44 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aYzNB-00036o-D3 for pgsql-bugs@postgresql.org; Thu, 25 Feb 2016 17:06:42 +0000 Received: from intern.anarazel.de (104-2-144-147.lightspeed.sntcca.sbcglobal.net [104.2.144.147]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 3BF8E3B2D70; Thu, 25 Feb 2016 18:06:40 +0100 (CET) Date: Thu, 25 Feb 2016 09:06:38 -0800 From: Andres Freund To: "Shulgin, Oleksandr" Cc: Alvaro Herrera , chris.tessels@inergy.nl, Pg Bugs Subject: Re: BUG #13985: Segmentation fault on PREPARE TRANSACTION Message-ID: <20160225170638.z3yorrvkwpfuo2t5@alap3.anarazel.de> References: <20160224125824.2573.27524@wrigleys.postgresql.org> <20160224205237.GA438345@alvherre.pgsql> <20160224215221.bbbduc5nelq7tf6s@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -1.9 (-) 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 On 2016-02-25 09:02:07 +0100, Shulgin, Oleksandr wrote: > On Wed, Feb 24, 2016 at 10:52 PM, Andres Freund wrote: > > > On 2016-02-24 17:52:37 -0300, Alvaro Herrera wrote: > > > chris.tessels@inergy.nl wrote: > > > > > > > Core was generated by `postgres: mailinfo_ow mailinfo_ods > > 10.50.6.6(4188'. > > > > Program terminated with signal 11, Segmentation fault. > > > > > > > > #0 MinimumActiveBackends (min=50) at procarray.c:2472 > > > > 2472 if (pgxact->xid == InvalidTransactionId) > > > > > > It's not surprising that you're not able to make this crash > > > consistently, because it looks like the problem might be in concurrent > > > modifications to the PGXACT array. This routine, MinimumActiveBackends, > > > walks the PGPROC array explicitely without locks. There are comments > > > indicating that this is safe, but evidently something has slipped in > > > there. > > > > > > Apparently this code is trying to dereference an invalid pgxact, but > > > it's not clear to me how this happens. Those structs are allocated in > > > advance, and they are referenced in the code via array indexes, so even > > > if the pgxact doesn't actually hold data about a valid transaction, > > > dereferencing the XID shouldn't cause a crash. > > > > Well, that code is pretty, uh, questionable. E.g. for > > int pgprocno = > > arrayP->pgprocnos[index]; > > volatile PGPROC *proc = &allProcs[pgprocno]; > > volatile PGXACT *pgxact = &allPgXact[pgprocno]; > > there's no guarantee that pgprocno is actually the same index for both > > lookups and the following > > if (pgprocno == -1) > > continue; /* do not count > > deleted entries */ > > check. It's perfectly reasonable for a compiler to reload pgprocno from > > memory, or just always reference it via memory. > > > > Hm... this is against my understanding of what a compiler could (or > should) do. Do you have a documentation reference or other evidence? Which part does not conform to your expectations? Moving stores/loads around from where they're apparently happening in the C program? Repeatedly reading from memory instead of storing something on the stack? All of those are side effect free for single-threaded programs, which pretty much is the gold standard for doing optimizations in C (at least pre-C11, but even there the above all would be possible). Regards, Andres -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs