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 1iK8mD-00079k-Qv for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Oct 2019 22:25:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJiLJ-0005Kd-HA for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Oct 2019 18:11:45 +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 1iJiK5-0005IM-B7 for pgsql-hackers@lists.postgresql.org; Sun, 13 Oct 2019 18:10:29 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJiK2-0007q0-8N for pgsql-hackers@lists.postgresql.org; Sun, 13 Oct 2019 18:10:28 +0000 Received: by mail-ed1-x543.google.com with SMTP id r16so12820395edq.11 for ; Sun, 13 Oct 2019 11:10:25 -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=mMXn476q51yQGShLcCPHdbZamS8j9PMpzy2qau36ELg=; b=pAHYFf0zqLtemugw/KBJzSx2GxGqpGGEHrOMJ9ZfWyEIyPld5xUdpsci0CnEmNBbzg sWAQuM8/3tcRmMVyAApaq/7a1FzeTq9LeQD2r40E8Ie9qN9isgxqskMxTZrponXwoiXn XHhOyZBf2zDmKiAkYdo3CNl8MXo7vmfQKXGah+GrFCS0rp/TjruOc456qPXy1LVtv0XL wapCLhWKYnqCOBa4I3IodsbvG5kfSzUlDGecbC7FxU3Vuf3sWvqGLbYRJXdo0X1pQYv8 xfF4fJQdZsGLkPKDpPPBULCL95iI9KhpneFRwaSCif7HBedcgpSbgsHcPS26O7SUTBpZ wtCA== 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=mMXn476q51yQGShLcCPHdbZamS8j9PMpzy2qau36ELg=; b=OwaH80VN77yAOJ0g7UX8a2iLbUEBQ6ywl+uklvDEGEAHMdhQQNa9fFKVpH8OP4VDt2 NkrwjCxeFJGp82osGdtUTusPrQl9Ga5g8PXP2qj3w+aXQPj3vnZz4p8giUkWrvvRHIUZ Qv8Hfwe1E0MY2eBRrboA+sODT3yVyh0LWsHnoJIGR9nn8qw5shfbe6YA13GJh9ggzYVT kWx06T3gvXZFZ9m5vVtUo+cfJtgXwnN2bpectMh0+k4cXqAVGzRS6i7cgBn+qpVYaxqg UgIrx8k8DbPUt+QAmuvUkTBfNbaGIj9AvLkrJ4ER8GIhvp4oi8dRnJl3VrhLpB4xGs1R IPkQ== X-Gm-Message-State: APjAAAWorcf7iu2Ev/vs7lWTGlhJZoOb3e4h5jiEmrNH5Nna3IWEVWKe GcRJLbsvYR9UDKdjAxCWPYEvDQ== X-Google-Smtp-Source: APXvYqyqcYLARdBZQ9P9SKxqPClFHYJR+2rZG3SwKQ+cuHpOsovNjnlluTW11ybc7BlrBHCiCp4fPg== X-Received: by 2002:a17:906:9487:: with SMTP id t7mr24861045ejx.231.1570990224074; Sun, 13 Oct 2019 11:10:24 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([212.92.114.248]) by smtp.gmail.com with ESMTPSA id v24sm1987211ejr.22.2019.10.13.11.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2019 11:10:22 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id B5A6A3009AD; Sun, 13 Oct 2019 15:10:21 -0300 (-03) Date: Sun, 13 Oct 2019 15:10:21 -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: <20191013181021.GA10785@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="sdtB3X0nJg68CQEu" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191013162426.GF4475@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 --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --sdtB3X0nJg68CQEu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="reindex-crash.patch" diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 70f9b6729a..5f4ee86f70 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -388,8 +388,9 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool 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..63c4188efc 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -908,8 +908,9 @@ WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool 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++; --sdtB3X0nJg68CQEu--