Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qMW0E-002aAh-Jd for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Jul 2023 15:55:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qMW0C-00BI5A-Jc for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Jul 2023 15:55:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qMW0C-00BI4W-AA for pgsql-hackers@lists.postgresql.org; Thu, 20 Jul 2023 15:55:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qMW05-000fzZ-Nz for pgsql-hackers@lists.postgresql.org; Thu, 20 Jul 2023 15:55:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 36KFtWXd584105; Thu, 20 Jul 2023 11:55:32 -0400 From: Tom Lane To: Justin Pryzby cc: pgsql-hackers@lists.postgresql.org Subject: Re: pg15.3: dereference null *plan in CachedPlanIsSimplyValid/plpgsql In-reply-to: References: Comments: In-reply-to Justin Pryzby message dated "Thu, 20 Jul 2023 10:42:49 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <584103.1689868532.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 20 Jul 2023 11:55:32 -0400 Message-ID: <584104.1689868532@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Justin Pryzby writes: > A production instance crashed like so. Oh, interesting. Apparently we got past the "Has cache invalidation fired on this plan?" check: if (!plansource->is_valid || plan !=3D plansource->gplan || !plan->is_= valid) return false; because "plan" and "plansource->gplan" were *both* null, which is a case the code wasn't expecting. plansource.c seems to be paranoid about gplan possibly being null everywhere else but here :-( > Note that the prior query seems to have timed out in the same / similar = plpgsql > statement: Hm. Perhaps that helps explain how we got into this state. It must be some weird race condition, given the lack of prior reports. Anyway, adding a check for plan not being null seems like the obvious fix. regards, tom lane