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 1n91jy-0003SG-1n for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Jan 2022 09:22:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n91jw-0006xN-UO for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Jan 2022 09:22:20 +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 1n91ju-0006xE-PL for pgsql-hackers@lists.postgresql.org; Sun, 16 Jan 2022 09:22:20 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n91jq-0004Q4-6H for pgsql-hackers@postgresql.org; Sun, 16 Jan 2022 09:22:18 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6BA3F3200AB0; Sun, 16 Jan 2022 04:22:10 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 16 Jan 2022 04:22:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:subject:message-id:mime-version:content-type; s= fm3; bh=FVQcWVgj2El5VBq2hykGf56M3vGS0r8A/QIL6lu+y+0=; b=gU58Tb9Q SIdI3tGZMGlkU97k5bxI7JlgbF+yfmskUlYHWNZhYD2K6oFgSi1iFtmjHUXInCEv t4Apg86fAe9OoDuMQeRGaiOVip+fTLQPUwCJjNO8lSz183dOWT7PxtcYOTM2a1Pt GOWVxYUUxTsRLfgqsjSTcsMsU41/ZOqYZJKeIjhY1FBKGnvmrvwRvpqeYepNrgSZ /4f3k538IKu85FA6DhOt8Px9vARpOn5LD/qHCevyNrX8HcnWR1pPvQpdq4nW721Y cbvfEsA0THFYYwrswF+WfmDb6iEtbuAkipWLRhmduR9P2dj0x0vIWOZETUCMREUZ 3b9zRtE/G0pFCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=FVQcWVgj2El5VBq2hykGf56M3vGS0 r8A/QIL6lu+y+0=; b=UWdROMlUNPrJJIOvQ3trx+jnLfAmxhB0avWYOrsh2VWBv TXE0KBw+vnPWRGZyjQ/t+7VYV2HdWwzFRoxiiteTvHVzjzBYUd0QzGqz0AtsrBNR NK/6WE132+rrBywvUYYb2SkvPVOkG4UHzIPbYK59lP5JgnB7NTQdBlnkx+s3bO/O VWV2An3Hv2npzuU//Gvji2jtrxTlVtys3p0RETUCVMj/saNtf1gN/mj3OWE8Andm OFJxCw/WMd17G+dmtxpfClJNPRJy9ADBPvioK9fvbn9mumTc9cKzIJ3SqKExL6zS J05OVcZ/MRHNyuEF42PXliGRsvHXl0wdK9huOYJ8w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrtdelgddtvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugesthdtredttddtvdenucfhrhhomheptehnughrvghsucfh rhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrthhtvg hrnhepuddukedvvefhhfegtedtgeffgfekgfelgedtkedtteetjeeikeejteelkefgteel necuffhomhgrihhnpehpohhsthhgrhdrvghsnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jan 2022 04:22:09 -0500 (EST) Date: Sun, 16 Jan 2022 01:22:07 -0800 From: Andres Freund To: pgsql-hackers@postgresql.org, Magnus Hagander , Tom Lane Subject: pg_basebackup WAL streamer shutdown is bogus - leading to slow tests Message-ID: <20220116092207.me3kihxgjcbyshae@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I was wondering in [1] what we could do about the slowest tests on windows. On 2021-12-31 11:25:28 -0800, Andres Freund wrote: > Picking a random successful cfbot run [1] I see the following tap tests taking > more than 20 seconds: > > 67188 ms pg_basebackup t/010_pg_basebackup.pl > 59710 ms recovery t/001_stream_rep.pl Comparing these times to measurements taken on my normal linux workstation, something seemed just *very* off, even with a slow CI instance and windows in the mix. A bunch of printf debugging later, I realized the problem is that several of the pg_basebackups in tests take a *long* time. E.g. for t/001_stream_rep.pl the backups from the standby each take just over 10s. That's awfully specific... # Taking pg_basebackup my_backup from node "standby_1" # Running: pg_basebackup -D C:/dev/postgres/./tmp_check/t_001_stream_rep_standby_1_data/backup/my_backup -h C:/Users/myadmin/AppData/Local/Temp/yba26PBYX1 -p 59181 --checkpoint fast --no-sync --label my_backup -v # ran in 10.145s # Backup finished This reproduceably happens and it's *not* related to the socket shutdown() changes we've been debugging lately - even after a revert the problem persists. Because our logging for basebackups is quite weak, both for server and client side, I needed to add a fair bit more debugging to figure it out: pg_basebackup: wait to finish at 0.492 pg_basebackup: waiting for background process to finish streaming ... pg_basebackup: stream poll timeout 10.112 The problem is that there's just no implemented way to timely shutdown the WAL streaming thread in pg_basebackup. The code in pg_basebackup.c says: if (verbose) pg_log_info("waiting for background process to finish streaming ..."); ... /* * On Windows, since we are in the same process, we can just store the * value directly in the variable, and then set the flag that says * it's there. */ ... xlogendptr = ((uint64) hi) << 32 | lo; InterlockedIncrement(&has_xlogendptr); But just setting a variable doesn't do much if the thread is in HandleCopyStream()->CopyStreamPoll()->select() The only reason we ever succeed shutting down, without more WAL coming in, is that pg_basebackup defaults to sending a status message every 10 seconds. At which point the thread sees has_xlogendptr = true, and shuts down. A test specific workaround would be to just add --status-interval=1 to Cluster.pm::backup(). But that seems very unsatisfying. I don't immediately see a solution for this, other than to add StreamCtl->stop_event (mirroring ->stop_socket) and then convert CopyStreamPoll() to use WaitForMultipleObjects(). Microsoft's select() doesn't support pipes and there's no socketpair(). Any more straightforward ideas? From a cursory look at history, it used to be that pg_basebackup had this behaviour on all platforms, but it got fixed for other platforms in 7834d20b57a by Tom (assuming the problem wasn't present there). Greetings, Andres Freund [1] https://postgr.es/m/20211231192528.wirwj4qaaw3ted5g%40alap3.anarazel.de