Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dz8h6-0008Qz-Kw for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Oct 2017 21:56:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dz8h5-0002Aq-Uo for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Oct 2017 21:56:07 +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_2) (envelope-from ) id 1dz8fY-0007mX-1U for pgsql-hackers@postgresql.org; Mon, 02 Oct 2017 21:54:32 +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.84_2) (envelope-from ) id 1dz8fU-0003uW-W6 for pgsql-hackers@postgresql.org; Mon, 02 Oct 2017 21:54:31 +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 v92LsKVU001410; Mon, 2 Oct 2017 17:54:20 -0400 From: Tom Lane To: Andres Freund cc: Andreas Seltenreich , pgsql-hackers@postgresql.org, Alvaro Herrera , Michael Paquier Subject: Re: [sqlsmith] stuck spinlock in pg_stat_get_wal_receiver after OOM In-reply-to: <665.1506980082@sss.pgh.pa.us> References: <87h8vhtgj2.fsf@ansel.ydns.eu> <20171002210805.x4lxxmarluen6rfg@alap3.anarazel.de> <459.1506979825@sss.pgh.pa.us> <20171002213215.4e3iwt7oh5wdjqm2@alap3.anarazel.de> <665.1506980082@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 02 Oct 2017 17:34:42 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1408.1506981260.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 02 Oct 2017 17:54:20 -0400 Message-ID: <1409.1506981260@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org I wrote: > If this is the only problem then I'd agree we should stick to a spinlock > (I assume the strings in question can't be very long). I was thinking > more about what to do if we find other violations that are harder to fix. I took a quick look through walreceiver.c, and there are a couple of obvious problems of the same ilk in WalReceiverMain, which is doing this: walrcv->lastMsgSendTime =3D walrcv->lastMsgReceiptTime =3D walrcv->latestW= alEndTime =3D GetCurrentTimestamp(); (ie, a potential kernel call) inside a spinlock. But there seems no real problem with just collecting the timestamp before we enter that critical section. I also don't especially like the fact that just above there it reaches elog(PANIC) with the lock still held, though at least that's a case that should never happen. Further down, it's doing a pfree() inside the spinlock, apparently for no other reason than to save one "if (tmp_conninfo)". I don't especially like the Asserts inside spinlocks, either. Personally, I think if those conditions are worth testing then they're worth testing for real (in production). Variables that are manipulated by multiple processes are way more likely to assume unexpected states than local variables. I'm also rather befuddled by the fact that this code sets and clears walrcv->latch outside the critical sections. If that field is used by any other process, surely that's completely unsafe. If it isn't, why is it being kept in shared memory? regards, tom lane --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers