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 1fDLVp-00039d-92 for pgsql-hackers@arkaria.postgresql.org; Tue, 01 May 2018 02:59:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fDLVm-0004YY-HV for pgsql-hackers@arkaria.postgresql.org; Tue, 01 May 2018 02:59:26 +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 1fDLVm-0004YP-2n for pgsql-hackers@lists.postgresql.org; Tue, 01 May 2018 02:59:26 +0000 Received: from mail-pf0-x234.google.com ([2607:f8b0:400e:c00::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fDLVh-0005vq-FB for pgsql-hackers@lists.postgresql.org; Tue, 01 May 2018 02:59:24 +0000 Received: by mail-pf0-x234.google.com with SMTP id j11so8240981pff.10 for ; Mon, 30 Apr 2018 19:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=tqRMGOg77f77fF7ueEh3XSMW01YzxFvtEPpmSbs0A7Q=; b=L3SA4+6JORCbhHg8drY7aTE8k0+FzGJ5t4rQj0xoa8B8+C0FeRcTZWHbqSUp0nyHG0 gqynOmEue+2ecpVeHeP0XJLpvojrtYLYawbZvoQSMpPfiz1y+czjJCY9aCd/vZqBQFm0 kgkwDhcpkw2a4cmbdcUOoFgJLNvL9K3lybQdU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tqRMGOg77f77fF7ueEh3XSMW01YzxFvtEPpmSbs0A7Q=; b=G4p6d+YxQgTiVoYQpMi6PGI5W/W1omBlRUfb9L7M/GhCshiXwpba/qcrQP7SFDZGDr aKL1NnKwaDBFhOOYBbAWSej0b8S7WwnosBd7CKJPqP/5jjSIGwuo0TPEFw8mpbaCXj3X ZS/o2XM2gDmd6UhFn4ShrZmzC/HTyEbxsksWq3zWMGe2yxzbXxjuuT29ulyZlR+aqpZa ZuFXnkVZpY+RgASd2nJaClRlsYm4iguL3YIz14ecUp83hoN0Du+KL24bZRfUi7As0aLm bWF6r+tZs0EUURNOrQhjSk6JOnAXT5LEBAKSN8sSZFtDMDcNNJpAOdztjIMhsbvuEk3a IY9Q== X-Gm-Message-State: ALQs6tCRwR2hDaKCloRpYKH79y20UstXDBVGRjzKnuQLoJ/3AcM/NiAZ JUgoPTOycDoVHQdhQ3PJNmzlCA== X-Google-Smtp-Source: AB8JxZpGumFtOCs362vCvtTpFaTW/mMhmOy5/2mmiIVPHgVXZ1j6M8q1zjf5NdRKeMAoFIMY80jVkw== X-Received: by 10.98.20.195 with SMTP id 186mr14096676pfu.92.1525143558577; Mon, 30 Apr 2018 19:59:18 -0700 (PDT) Received: from rfd.leadboat.com (c-73-158-248-138.hsd1.ca.comcast.net. [73.158.248.138]) by smtp.gmail.com with ESMTPSA id l26sm20038393pfj.70.2018.04.30.19.59.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 19:59:17 -0700 (PDT) Date: Mon, 30 Apr 2018 19:59:14 -0700 From: Noah Misch To: Tom Lane Cc: Heath Lord , Thomas Munro , Stephen Frost , PostgreSQL Hackers Subject: Re: "could not reattach to shared memory" on buildfarm member dory Message-ID: <20180501025914.GA2777381@rfd.leadboat.com> References: <25495.1524517820@sss.pgh.pa.us> <20180423231855.GK27724@tamriel.snowman.net> <20180424070646.GA2693533@rfd.leadboat.com> <17897.1525108069@sss.pgh.pa.us> <29823.1525132900@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <29823.1525132900@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Apr 30, 2018 at 08:01:40PM -0400, Tom Lane wrote: > It's clear from dory's results that something is causing a 4MB chunk > of memory to get reserved in the process's address space, sometimes. > It might happen during the main MapViewOfFileEx call, or during the > preceding VirtualFree, or with my map/unmap dance in place, it might > happen during that. Frequently it doesn't happen at all, at least not > before the point where we've successfully done MapViewOfFileEx. But > if it does happen, and the chunk happens to get put in a spot that > overlaps where we want to put the shmem block, kaboom. > > What seems like a plausible theory at this point is that the apparent > asynchronicity is due to the allocation being triggered by a different > thread, and the fact that our added monitoring code seems to make the > failure more likely can be explained by that code changing the timing. > But what thread could it be? It doesn't really look to me like either > the signal thread or the timer thread could eat 4MB. syslogger.c > also spawns a thread, on Windows, but AFAICS that's not being used in > this test configuration. Maybe the reason dory is showing the problem > is something or other is spawning a thread we don't even know about? Likely some privileged daemon is creating a thread in every new process. (On Windows, it's not unusual for one process to create a thread in another process.) We don't have good control over that. > I'm at a loss for a reasonable way to fix it > for real. Is there a way to seize control of a Windows process so that > there are no other running threads? I think not. > Any other ideas? PostgreSQL could retry the whole process creation, analogous to internal_forkexec() retries. Have the failed process exit after recording the fact that it couldn't attach. Make the postmaster notice and spawn a replacement. Give up after 100 failed attempts.