Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJjTA-0003cT-75 for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Oct 2019 19:23:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJjQ3-0007nL-12 for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Oct 2019 19:20:43 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJjO6-0007m6-Ko for pgsql-hackers@lists.postgresql.org; Sun, 13 Oct 2019 19:18:42 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJjO2-0008OH-N3 for pgsql-hackers@lists.postgresql.org; Sun, 13 Oct 2019 19:18:41 +0000 Received: by mail-ed1-x544.google.com with SMTP id v8so12969581eds.2 for ; Sun, 13 Oct 2019 12:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=bKnPr+Dle/dZqQpYDvSMWsEgArHEG3Suekc6Y4sGMPU=; b=MKmzgWc9r4QCxPyBl0NR8YzUnQkOKHkrtCxHQ3hseVVrR5tK3RGSBoiKx5haSNR8He 5vGh2ZmSS8PsjUfv/7wsgYcTJFEch/0e8KvZ8jiRlFWIAF1xU0mzVBf79q1j3wjbOrnu qpmsjYqaPMU2kmtYXCy7ptyjqibkV+gyVf5gHDpl2ebRA2mpumdknKRODNT3qJ2zsOVl ZtJCCuECaFpD8DIE2REI6MV3mPh0r4LC3fLpdGpWRRsybYaFzkeV9TCBavHjwWRn9S2l 89kMAkTeok7XtU/aHynt3gmLsIhnyiOpb3TO6tX84pANG4bmkURgj1vU2p3OvLBkqSpv jTnQ== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=bKnPr+Dle/dZqQpYDvSMWsEgArHEG3Suekc6Y4sGMPU=; b=t+PgYq9e1dDw0UewwPeVIDODhxbQ83Pez/xFJcf2jEkr3JCUgkZw0W5gKLBvnAPw4+ joxit723bpENOswRHrJJtHrv5V7u+PDH5MuYXGtdk4x2Nbx5gFbeTtNRpYaysYST8u6A OtF0pviHMrQ+xyZ+WEJuWZ9aHroAo5GNY/5Uzr/CZDz/n5+jJUvGpkKy+8wOPVv6KPiR YR7gaEC6mr+8I6zj1UioolvIJ9mSfEYS4X+eSabaSmkm4H5cT8S0fLswKMBlOPCi/IOX xoZgd6f1vHsxIUvcke2czDdZiann/QZLBg3efAedXO3X4b2RQI6I6Ha1MIZxGEXZfD17 SmCw== X-Gm-Message-State: APjAAAV6QE5Xju1gAPSob3IcmOcuYqBuJywudrC/SyD1aFFX65v7edlE UHDZnYGz+EUAoFvrkzqCPsOdWg== X-Google-Smtp-Source: APXvYqzx4+tfMwPSDso3sgaSa0lXjJhBZ4bn6rhPPvE/HZhJcPNqI4aeR912b4KKtUUTrO5A24UokA== X-Received: by 2002:aa7:d04c:: with SMTP id n12mr24123554edo.52.1570994316348; Sun, 13 Oct 2019 12:18:36 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([212.92.114.248]) by smtp.gmail.com with ESMTPSA id z1sm402074eji.49.2019.10.13.12.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2019 12:18:35 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 6CD9A3009AD; Sun, 13 Oct 2019 16:18:34 -0300 (-03) Date: Sun, 13 Oct 2019 16:18:34 -0300 From: Alvaro Herrera To: Justin Pryzby Cc: Michael Paquier , pgsql-hackers@lists.postgresql.org, Peter Eisentraut , Andreas Karlsson Subject: Re: v12.0: segfault in reindex CONCURRENTLY Message-ID: <20191013191834.GA11662@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191013181450.GG4475@telsasoft.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Oct-13, Justin Pryzby wrote: > On Sun, Oct 13, 2019 at 03:10:21PM -0300, Alvaro Herrera wrote: > > On 2019-Oct-13, Justin Pryzby wrote: > > > > > Looks like it's a race condition and dereferencing *holder=NULL. The first > > > crash was probably the same bug, due to report query running during "reindex > > > CONCURRENTLY", and probably finished at nearly the same time as another locker. > > > > Ooh, right, makes sense. There's another spot with the same mistake ... > > this patch should fix it. > > I would maybe chop off the 2nd sentence, since conditionalizing indicates that > we do actually care. > > + * If requested, publish who we're going to wait for. This is not > + * 100% accurate if they're already gone, but we don't care. True. And we can copy the resulting comment to the other spot. (FWIW I expect the crash is possible not just in reindex but also in CREATE INDEX CONCURRENTLY.) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --vtzGhvizbBRQ85DL Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="reindex-crash-2.patch" diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 70f9b6729a..589b8816a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -384,12 +384,14 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress) if (VirtualTransactionIdIsValid(old_snapshots[i])) { + /* If requested, publish who we're going to wait for. */ if (progress) { PGPROC *holder = BackendIdGetProc(old_snapshots[i].backendId); - pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID, - holder->pid); + if (holder) + pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID, + holder->pid); } VirtualXactLock(old_snapshots[i], true); } diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index 4682438114..1dd0e5e957 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -900,16 +900,14 @@ WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress) while (VirtualTransactionIdIsValid(*lockholders)) { - /* - * If requested, publish who we're going to wait for. This is not - * 100% accurate if they're already gone, but we don't care. - */ + /* If requested, publish who we're going to wait for. */ if (progress) { PGPROC *holder = BackendIdGetProc(lockholders->backendId); - pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID, - holder->pid); + if (holder) + pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID, + holder->pid); } VirtualXactLock(*lockholders, true); lockholders++; --vtzGhvizbBRQ85DL--