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 1jHiHu-0004do-Sw for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2020 06:16:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHiHt-0006GH-M3 for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2020 06:16:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jHiHt-0006G9-2o for pgsql-hackers@lists.postgresql.org; Fri, 27 Mar 2020 06:16:13 +0000 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jHiHl-0002Sr-S4 for pgsql-hackers@postgresql.org; Fri, 27 Mar 2020 06:16:11 +0000 Received: by mail-qt1-x82e.google.com with SMTP id c14so7752772qtp.0 for ; Thu, 26 Mar 2020 23:16:05 -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=ujj00il5BHBnffHp+FLjGN/7uN/K5CjfIeyZAzqSmsc=; b=khaLIHf5YJNbYOe7jd01aw0IzmsKiN5JuDyR/6Vqqpw0/njYd7PV0JiTyPAR9B8NA3 BL4MfkPoVhkH4tIhm1TSppzO4gEgrk1T9ICOLs/9vc02nXt31z2uYt9R+OZ15/XTTTMf xG5XGmQ4Z/Kxp7wyR6Bh1WSLxPbP/hi3kiPnP4HB+dndNqzjVaAHdrKi7EUYdrJyoHus LlRd6zg8IdNhn4ebG/82CJ9Twz56UBcIyvXIG6jm8pFMQAF/8qmw1QJ6A4NOKEgrQ8fg VTLhfxdfqD3KSLfZeTmzYYKpqUrGPHddw2HGvvcOksSQynNa6UhGE+M+L2UmOdqs3r99 wVQg== 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=ujj00il5BHBnffHp+FLjGN/7uN/K5CjfIeyZAzqSmsc=; b=ny3oIXOz7sWQJRLJ2oNet9e9YMdL28fTMadILpHKojCd27YbiYyZTdGfHXFhiecRYo K1a+KZAskprpIf5TaG+eF5vXYucBFr9I39oOLPphTWAowj7hT0FIzy35nvZTkkiVEXt7 qrHysfkyolPxxEtu6PjIn82nvkefT74tsXkLIxQ00o8FNQQED8mz6O8wPywS7FV15LeW Y6iSF3dx/BbTxrkLsOt24uh35TnSK/3xr1w6U/dKtP1TOXiLJfElbNtzzzVuqbQnNuSm TyZlRJ6SuDtTsfkt93Ss1yW/O8d9nN+qVFcsiYg5D3io+p+/gXZOuiG9Y2avRcAbBjFs 00Qw== X-Gm-Message-State: ANhLgQ3Q52BCaR0P2Jil4+MLf0K/H8FYNwvAFduOu2W0blN6giuQmyyI 3donuoz3vd+Op4tpgpnXv1IJ+Q== X-Google-Smtp-Source: ADFU+vtmMGA63/g+Q4dnX5MNEcrJr2n2EMDoipOoR6FqckX++6n2maockn4QXnm1s5mPZF1jvlcFvw== X-Received: by 2002:ac8:7518:: with SMTP id u24mr12673400qtq.283.1585289764255; Thu, 26 Mar 2020 23:16:04 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id t23sm3264913qtj.63.2020.03.26.23.16.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2020 23:16:03 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 5E10A80096B; Fri, 27 Mar 2020 01:16:01 -0500 (CDT) Date: Fri, 27 Mar 2020 01:16:01 -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: <20200327061601.GE20103@telsasoft.com> References: <20200325124155.GU21443@telsasoft.com> <20200326044115.GB28385@telsasoft.com> <20200326150457.GB17431@telsasoft.com> <20200326221752.GR17431@telsasoft.com> <20200327044424.GD20103@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200327044424.GD20103@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Mar 26, 2020 at 11:44:24PM -0500, Justin Pryzby wrote: > 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. If "phase" is updated before "indname", I'm able to induce a synthetic crash like this: +if (errinfo->phase==VACUUM_ERRCB_PHASE_VACUUM_INDEX && errinfo->indname==NULL) +{ +kill(getpid(), SIGINT); +pg_sleep(1); // that's needed since signals are delivered asynchronously +} And another crash if we do this after pfree but before setting indname. +if (errinfo->phase==VACUUM_ERRCB_PHASE_VACUUM_INDEX && errinfo->indname!=NULL) +{ +kill(getpid(), SIGINT); +pg_sleep(1); +} I'm not sure if those are possible outside of "induced" errors. Maybe the function is essentially atomic due to no CHECK_FOR_INTERRUPTS or similar? -- Justin