Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbFda-000127-Cc for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Apr 2022 05:52:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nbFdZ-0007vZ-9H for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Apr 2022 05:52:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbFdY-0007vP-Oy for pgsql-hackers@lists.postgresql.org; Mon, 04 Apr 2022 05:52:25 +0000 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nbFdW-0000S7-1E for pgsql-hackers@lists.postgresql.org; Mon, 04 Apr 2022 05:52:23 +0000 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-e1e5e8d9faso4191072fac.4 for ; Sun, 03 Apr 2022 22:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mjp+IZHwMeDFPMhbN5AJQRcHUmVjI7d3UndpE4+tJ/4=; b=Wf/BDKZYhH4fdxKxG3IHysgjSh9vGjPtxexdJccVgnRF5nDsSeQtPcJAmJU2OgKBPc jtr2CqBrffXOk1/2V8cY3gHw1IyJBpjy+UlOwg29uGfvAOfRM0Zyz4WzKtxAa4BxKrL/ zT4mBptccjyLRqcJy07Er9b4zalfh3cJXg7ug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mjp+IZHwMeDFPMhbN5AJQRcHUmVjI7d3UndpE4+tJ/4=; b=es6lwtRpODM1apu/oYlikRCwO2xJmO4mfy53lDXQ+dJMRfsFog5ScNzoI3c8kWJA7L CwJnCe5L9LYKoNItO72wRT6Fe8W2H3aIFtWlWvzfvmj+tK2/y0dnKUiOQrQny5/VCLdu y8VQEhPpVpl4+5pe30Kv0Ma+Sjhl11FRy5B4o9uyHWTtDJE/WqsE5kz4mWmzyyvzC3uv MWX17HmllYJOklx/5tbEfB4JqHzcf9120VvklFsPbMNZgXNOjhVSV8TKvTXDpidvYsvI 2Loqv/JUSLlBDc5/Vo9DT0RitNENZMksiXdxUkYq2BNyVEGPA8LPb8cjXVUneENo7622 xpsg== X-Gm-Message-State: AOAM532lGT0dP9qUsnciU6eggZfbSpXtejMRqLxvVpxyYCXxUeCldrm4 3RUKyHiDij5jKR7a+9EF6eW1qw== X-Google-Smtp-Source: ABdhPJyIWOyLlG0iKEIawIBxDUfbhV7I7k7/eqWORHLlsJQEX6PgbFDjwjv7j0W/cOe1R7raj6l1mw== X-Received: by 2002:a05:6870:4413:b0:e1:f3cc:37ea with SMTP id u19-20020a056870441300b000e1f3cc37eamr2098794oah.76.1649051541435; Sun, 03 Apr 2022 22:52:21 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id e24-20020a056808111800b002f75ced8d2csm3863227oih.7.2022.04.03.22.52.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Apr 2022 22:52:21 -0700 (PDT) Date: Sun, 3 Apr 2022 22:52:18 -0700 From: Noah Misch To: Andres Freund Cc: Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: Race condition in server-crash testing Message-ID: <20220404055218.GD3799006@rfd.leadboat.com> References: <1801850.1649047827@sss.pgh.pa.us> <20220404050721.sktsuearncwjo6hr@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220404050721.sktsuearncwjo6hr@alap3.anarazel.de> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Apr 03, 2022 at 10:07:21PM -0700, Andres Freund wrote: > On 2022-04-04 00:50:27 -0400, Tom Lane wrote: > > My pet dinosaur gaur just failed [1] in > > src/test/recovery/t/022_crash_temp_files.pl, which does this: > > > > ----- > > my $ret = PostgreSQL::Test::Utils::system_log('pg_ctl', 'kill', 'KILL', $pid); > > is($ret, 0, 'killed process with KILL'); > > > > # Close psql session > > $killme->finish; > > $killme2->finish; > > > > # Wait till server restarts > > $node->poll_query_until('postgres', undef, ''); > > ----- > > > > It's hard to be totally sure, but I think what happened is that > > gaur hit the in-hindsight-obvious race condition in this code: > > we managed to execute a successful iteration of poll_query_until > > before the postmaster had noticed its dead child and commenced > > the restart. The test lines after these are not prepared to see > > failure-to-connect. > > > > It's not obvious to me how to remove this race condition. > > Thoughts? > > Maybe we can use pump_until() with the psql that's not getting killed? With a > non-matching regex? That'd only return once the backend was killed by > postmaster, afaics? Sounds good; I suspect that will be better than any of the ideas I scratched down when https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=hoverfly&dt=2021-08-31%2015%3A00%3A52 failed the same way. For what it's worth, those were: - Check that pg_postmaster_start_time() has changed. But that runs into EPIPE trouble, requiring a write to a file or an eval{} to trap the EPIPE. - Likewise, but check "select checkpoint_lsn from pg_control_checkpoint();". - Poll pg_controldata until a new checkpoint happens. Compare checkpoint LSN. Use checkpoint_timeout=1h to avoid non-end-of-recovery checkpoints. - Poll logfile until "all server processes terminated; reinitializing". Can be fooled with certain log_min_messages settings, but so can our other log-scraping tests. - Grab the pid of e.g. the checkpointer and poll for that process to be gone. Can be fooled by PID reuse.