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 1ndKDb-0001Bv-QZ for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Apr 2022 23:10:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ndKDZ-0004SN-Cp for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Apr 2022 23:10:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ndKDZ-0004SE-2V for pgsql-hackers@lists.postgresql.org; Sat, 09 Apr 2022 23:10:09 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ndKDV-0008QS-L3 for pgsql-hackers@postgresql.org; Sat, 09 Apr 2022 23:10:08 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id AA40932019B4; Sat, 9 Apr 2022 19:10:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 09 Apr 2022 19:10:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; bh=SJxlH1tuHzS2GTLbhW99QmilA/9n7QEv2hFNr/ m3E9g=; b=3ZISZ3nnQAV173w+PFSPLv6GcUQlxktEiaRw5G3qORkjHon5a9X4pw xgzKqP22rcHimUIKx4WQxSJHEv5M6X7sGebZdnBLsm1OUrhoPJjpu0IM98xsxkf7 /H/Bmsv+53xyDDdXhCbcROkrVa6jYKRNZGLsEI98rUU3sBCkcAEcJsPrHJ2867ud 1zW/gTU6cJNKukYaeQ++eqmaJNpw4e1YvEoGfr+ymcJrVitPi6JEw93BmOalqSE6 Ygvgx4J9qD6TJQfpfvGZ/AfMGFdKTOoe2TD7KZV4wTCmBeZQAcdayc/IhIp19G1Z IgSTIxofIdcl/i1To1x+qRaGjw4Fp2JA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=SJxlH1tuHzS2GTLbh W99QmilA/9n7QEv2hFNr/m3E9g=; b=OGGfoDho1NjlLpspBxS7ViCCOgC1VKUDs TBRz/r4QGlrKdp6NXB3e1HzEwcnEGkcrjVz3IPnnpEsUcSgetCkvIJnF/pdCaC7z kMaz2sSosZtu6y7stRmKAVwp6QKmJwzNUPRljKq2wqpjbVAbRlJaQlXMI4DUVhPK qDx/SUPHiKF1yBj3Ab6z8ESsdJAoCZDwJEziHnSS8ZjL6CHTbnRTLwxAJH1UcXTW CZ7Vh4+OnOjutJAOE7Tg3nRobO6tR450ipochsGIOhA8ccx1E4C8/2HCJQ5q9EwB f0cTO8jLfmdy8iM5FZ/BFZ3f5t48G19QnsE7X44JLJexe6SpIChzg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudekfedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedukefhkeelueegveetheelffffjeegleeuudelfeefuedtleffueejfffh ueffudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 9 Apr 2022 19:10:03 -0400 (EDT) Date: Sat, 9 Apr 2022 16:10:02 -0700 From: Andres Freund To: pgsql-hackers@postgresql.org, Thomas Munro Subject: Re: failures in t/031_recovery_conflict.pl on CI Message-ID: <20220409231002.mddrr7mtca7p55v5@alap3.anarazel.de> References: <20220409045515.35ypjzddp25v72ou@alap3.anarazel.de> <20220409050501.frejv2i46m54keem@alap3.anarazel.de> <20220409220054.fqn5arvbeesmxdg5@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220409220054.fqn5arvbeesmxdg5@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-04-09 15:00:54 -0700, Andres Freund wrote: > What are we expecting to wake the startup process up, once it does > SendRecoveryConflictWithBufferPin()? > > It's likely not the problem here, because we never seem to have even reached > that path, but afaics once we've called disable_all_timeouts() at the bottom > of ResolveRecoveryConflictWithBufferPin() and then re-entered > ResolveRecoveryConflictWithBufferPin(), and go into the "We're already behind, > so clear a path as quickly as possible." path, there's no guarantee for any > timeout to be pending anymore? > > If there's either no backend that we're still conflicting with (an entirely > possible race condition), or if there's e.g. a snapshot or database conflict, > there's afaics nobody setting the startup processes' latch. It's not that (although I still suspect it's a problem). It's a self-deadlock, because StandbyTimeoutHandler(), which ResolveRecoveryConflictWithBufferPin() *explicitly enables*, calls SendRecoveryConflictWithBufferPin(). Which does CancelDBBackends(). Which ResolveRecoveryConflictWithBufferPin() also calls, if the deadlock timeout is reached. To make it easier to hit, I put a pg_usleep(10000) in CancelDBBackends(), and boom: (gdb) bt #0 __futex_abstimed_wait_common64 (futex_word=futex_word@entry=0x7fd4cb001138, expected=expected@entry=0, clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=, cancel=cancel@entry=true) at ../sysdeps/nptl/futex-internal.c:87 #1 0x00007fd4ce5a215b in __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x7fd4cb001138, expected=expected@entry=0, clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=) at ../sysdeps/nptl/futex-internal.c:123 #2 0x00007fd4ce59e44f in do_futex_wait (sem=sem@entry=0x7fd4cb001138, abstime=0x0, clockid=0) at sem_waitcommon.c:112 #3 0x00007fd4ce59e4e8 in __new_sem_wait_slow64 (sem=0x7fd4cb001138, abstime=0x0, clockid=0) at sem_waitcommon.c:184 #4 0x00007fd4cf20d823 in PGSemaphoreLock (sema=0x7fd4cb001138) at pg_sema.c:327 #5 0x00007fd4cf2dd675 in LWLockAcquire (lock=0x7fd4cb001600, mode=LW_EXCLUSIVE) at /home/andres/src/postgresql/src/backend/storage/lmgr/lwlock.c:1324 #6 0x00007fd4cf2c36e7 in CancelDBBackends (databaseid=0, sigmode=PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, conflictPending=false) at /home/andres/src/postgresql/src/backend/storage/ipc/procarray.c:3638 #7 0x00007fd4cf2cc579 in SendRecoveryConflictWithBufferPin (reason=PROCSIG_RECOVERY_CONFLICT_BUFFERPIN) at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:846 #8 0x00007fd4cf2cc69d in StandbyTimeoutHandler () at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:911 #9 0x00007fd4cf4e68d7 in handle_sig_alarm (postgres_signal_arg=14) at /home/andres/src/postgresql/src/backend/utils/misc/timeout.c:421 #10 #11 0x00007fd4cddfffc4 in __GI___select (nfds=0, readfds=0x0, writefds=0x0, exceptfds=0x0, timeout=0x7ffc6e5561c0) at ../sysdeps/unix/sysv/linux/select.c:71 #12 0x00007fd4cf52ea2a in pg_usleep (microsec=10000) at /home/andres/src/postgresql/src/port/pgsleep.c:56 #13 0x00007fd4cf2c36f1 in CancelDBBackends (databaseid=0, sigmode=PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, conflictPending=false) at /home/andres/src/postgresql/src/backend/storage/ipc/procarray.c:3640 #14 0x00007fd4cf2cc579 in SendRecoveryConflictWithBufferPin (reason=PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK) at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:846 #15 0x00007fd4cf2cc50f in ResolveRecoveryConflictWithBufferPin () at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:820 #16 0x00007fd4cf2a996f in LockBufferForCleanup (buffer=43) at /home/andres/src/postgresql/src/backend/storage/buffer/bufmgr.c:4336 #17 0x00007fd4ceec911c in XLogReadBufferForRedoExtended (record=0x7fd4d106a618, block_id=0 '\000', mode=RBM_NORMAL, get_cleanup_lock=true, buf=0x7ffc6e556394) at /home/andres/src/postgresql/src/backend/access/transam/xlogutils.c:427 #18 0x00007fd4cee1aa41 in heap_xlog_prune (record=0x7fd4d106a618) at /home/andres/src/postgresql/src/backend/access/heap/heapam.c:8634 it's reproducible on linux. I'm lacking words I dare to put in an email to describe how bad an idea it is to call CancelDBBackends() from within a timeout function, particularly when the function enabling the timeout also calls that function itself. Before disabling timers. I ... Greetings, Andres Freund