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.92) (envelope-from ) id 1jHgrC-0002iK-NE for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2020 04:44:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHgrA-0007dO-DB for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2020 04:44:32 +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 1jHgrA-0007dH-48 for pgsql-hackers@lists.postgresql.org; Fri, 27 Mar 2020 04:44:32 +0000 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jHgr6-0007Zo-Nj for pgsql-hackers@postgresql.org; Fri, 27 Mar 2020 04:44:31 +0000 Received: by mail-qk1-x732.google.com with SMTP id e11so9580695qkg.9 for ; Thu, 26 Mar 2020 21:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=MleBqHuKc1oxxprAckUcT71gosJL3ACSU67oFKXfS84=; b=hBgNApWXHMz3cPqHTHtOpR+UEHiMV3uzdTPipx9Niw6Mwf8PTlLZjtLo1Cso9F2e9Q pf+qNNYzqmrl3S1L1gpdKLRUvmePc5SKJspLZzhyw2taUbYF++L9We957xUxidXHu3SR jHfFzKgoU2NMYxRur0JMbO2W5nzdWxQqILWiIypDXfrJYUz4p9CJlfFVgGoIltVrgr69 Od1ezFJIfDBUjxs7m5oJoVXutmIr0Rh73y7ZPGuI/qdwZspiw8LJx8c9tF/jT5loP3Qj k4Bqv07vTYygvDsGe5KJDsZ1At+VvOYEv8EMzOtJlA5PAx2ABk4ABlZoa40pOV04WWNf VNxQ== 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=MleBqHuKc1oxxprAckUcT71gosJL3ACSU67oFKXfS84=; b=E5GZUidL34cKn4EffWqPYzqfOSCL4BzOpl32psoemdsZ2n3L8TllE5Eu2nkb5KOTji g3U6Z6Wvdr88EbN3L5KW7jUiMRRod5/p0LbAdk8j3eQ2Ynzdm3MsQyNHBr8etr1630zv MW4L4xYJ6/Sgg0UoEux+T5LoNzRDYu0SCiXM0j88IryCRZ3FYU03HvQUSSaU9auBwno3 SNazYY9YvGbeY+boo0lvTpli+lbYAaXCcLNcqmUPODAv9dgmQj1xVaZ9jOk40S9p11nG Yf/3p38LB08AwRJQRojGOwkwuuz2VWcssTKNXFBfFaiVLMckOVcFVeBdVGGaLg4Eq4g6 /9Qw== X-Gm-Message-State: ANhLgQ2aXJMG5P1/o7SZjBd4YV5z3PyBCulHo0TiL9z9pe5PRAT2lVQT wdaXrmiyoLImq5NddUSBdsGUaA== X-Google-Smtp-Source: ADFU+vtcGClOzEMBhKL8LNMxxLT02ikzTbTBd8tgi+9v9+JogT5hFjtlEukvVLhgaATYEZkzSM/eBg== X-Received: by 2002:a37:4648:: with SMTP id t69mr11527648qka.299.1585284266614; Thu, 26 Mar 2020 21:44:26 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id z18sm3104139qtz.77.2020.03.26.21.44.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2020 21:44:25 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 3538D80096B; Thu, 26 Mar 2020 23:44:24 -0500 (CDT) Date: Thu, 26 Mar 2020 23:44:24 -0500 From: Justin Pryzby To: Amit Kapila Cc: Masahiko Sawada , Alvaro Herrera , Andres Freund , Michael Paquier , pgsql-hackers Subject: Re: error context for vacuum to include block number Message-ID: <20200327044424.GD20103@telsasoft.com> References: <20200325124155.GU21443@telsasoft.com> <20200326044115.GB28385@telsasoft.com> <20200326150457.GB17431@telsasoft.com> <20200326221752.GR17431@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Mar 27, 2020 at 09:49:29AM +0530, Amit Kapila wrote: > On Fri, Mar 27, 2020 at 3:47 AM Justin Pryzby wrote: > > > > > Hm, I was just wondering what happens if an error happens *during* > > > update_vacuum_error_cbarg(). It seems like if we set > > > errcbarg->phase=VACUUM_INDEX before setting errcbarg->indname=indname, then an > > > error would cause a crash. > > > > > Can't that be avoided if you check if cbarg->indname is non-null in > vacuum_error_callback as we are already doing for > VACUUM_ERRCB_PHASE_TRUNCATE? > > > > And if we pfree and set indname before phase, it'd > > > be a problem when going from an index phase to non-index phase. > > How is it possible that we move to the non-index phase without > clearing indname as we always revert back the old phase information? The crash scenario I'm trying to avoid would be like statement_timeout or other asynchronous event occurring between two non-atomic operations. I said that there's an issue no matter what order we set indname/phase; If we wrote: |cbarg->indname = indname; |cbarg->phase = phase; ..and hit a timeout (or similar) between setting indname=NULL but before setting phase=VACUUM_INDEX, then we can crash due to null pointer. But if we write: |cbarg->phase = phase; |if (cbarg->indname) {pfree(cbarg->indname);} |cbarg->indname = indname ? pstrdup(indname) : NULL; ..then we can still crash if we timeout between freeing cbarg->indname and setting it to null, due to acccessing a pfreed allocation. > > > So maybe we > > > have to set errcbarg->phase=VACUUM_ERRCB_PHASE_UNKNOWN while in the function, > > > and errcbarg->phase=phase last. > > I find that a bit ad-hoc, if possible, let's try to avoid it. I think we can do what you suggesting, if the callback checks if (cbarg->indname!=NULL). We'd have to write: // Must set indname *before* updating phase, in case an error occurs before // phase is set, to avoid crashing if we're going from an index phase to a // non-index phase (which should not read indname). Must not free indname // until it's set to null. char *tmp = cbarg->indname; cbarg->indname = indname ? pstrdup(indname) : NULL; cbarg->phase = phase; if (tmp){pfree(tmp);} Do you think that's better ? -- Justin