Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fDCHR-0007ui-MB for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Apr 2018 17:08:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fDCHP-0003ye-F9 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Apr 2018 17:07:59 +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.89) (envelope-from ) id 1fDCHP-0003yU-83 for pgsql-hackers@lists.postgresql.org; Mon, 30 Apr 2018 17:07:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fDCHL-0000Jw-JI for pgsql-hackers@lists.postgresql.org; Mon, 30 Apr 2018 17:07:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w3UH7nPT017898; Mon, 30 Apr 2018 13:07:49 -0400 From: Tom Lane To: Noah Misch cc: Thomas Munro , Stephen Frost , PostgreSQL Hackers Subject: Re: "could not reattach to shared memory" on buildfarm member dory In-reply-to: <20180424070646.GA2693533@rfd.leadboat.com> References: <25495.1524517820@sss.pgh.pa.us> <20180423231855.GK27724@tamriel.snowman.net> <20180424070646.GA2693533@rfd.leadboat.com> Comments: In-reply-to Noah Misch message dated "Tue, 24 Apr 2018 07:06:46 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17896.1525108069.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Apr 2018 13:07:49 -0400 Message-ID: <17897.1525108069@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk [ Thanks to Stephen for cranking up a continuous build loop on dory ] Noah Misch writes: > On Tue, Apr 24, 2018 at 11:37:33AM +1200, Thomas Munro wrote: >> Maybe try asking what's mapped there with VirtualQueryEx() on failure? > +1. An implementation of that: > https://www.postgresql.org/message-id/20170403065106.GA2624300%40tornado= .leadboat.com So I tried putting in that code, and it turns the problem from something that maybe happens in every third buildfarm run or so, to something that happens at least a dozen times in a single "make check" step. This seems to mean that either EnumProcessModules or GetModuleFileNameEx is itself allocating memory, and sometimes that allocation comes out of the space VirtualFree just freed :-(. So we can't use those functions. We have however proven that no new module gets loaded during VirtualFree or MapViewOfFileEx, so there doesn't seem to be anything more to be learned from them anyway. What it looks like to me is that MapViewOfFileEx allocates some memory and sometimes that comes out of the wrong place. This is, um, unfortunate. It also appears that VirtualFree might sometimes allocate some memory, and that'd be even more unfortunate, but it's hard to be certain; the blame might well fail on VirtualQuery instead. (Ain't Heisenbugs fun?) The solution I was thinking about last night was to have PGSharedMemoryReAttach call MapViewOfFileEx to map the shared memory segment at an unspecified address, then unmap it, then call VirtualFree, and finally call MapViewOfFileEx with the real target address. The idea here is to get these various DLLs to set up any memory allocation pools they're going to set up before we risk doing VirtualFree. I am not, at this point, convinced this will fix it :-( ... but I'm not sure what else to try. In any case, it's still pretty unclear why dory is showing this problem and other buildfarm members are not. whelk for instance seems to be loading all the same DLLs and more besides. regards, tom lane