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 1nK7ch-0005Jc-Mk for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Feb 2022 23:52:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nK7cA-0004YJ-Kb for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Feb 2022 23:52:10 +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 1nK7c8-0004YA-Rk for pgsql-hackers@lists.postgresql.org; Tue, 15 Feb 2022 23:52:10 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nK7c3-00012c-NT for pgsql-hackers@postgresql.org; Tue, 15 Feb 2022 23:52:08 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id C12623200946; Tue, 15 Feb 2022 18:51:59 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 15 Feb 2022 18:51:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc: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=fm3; bh=skmOsCcxFc8JdWNp/nRHwRHGex6ZV9knrDEapT YEVQk=; b=fb7swYUf2gehN2FeepSoxgw4taipZAthHgr89YY8m/Cf3d2b5Cc2YN owwosFnPsMNeBrj32ViH/F9YDj1dHqjp08VzgYAfVG902ggXsV8wG1IPKDx985w3 iLRTT/o2a0GPcYkxPlouedWyMPahxxZUMNSLtjrIunGVQ28cLr6cZsPGbLI96xvM Yh2KYbmo71BQoIC0iE0Ept78VdynXzFA9a3tXt8IA5VMbmSE3jXdY7jfu4wVAcZ9 Hr6P5sYr1i8Sr3sMLKYa+beA/xn+yy9AcRLcca8elgCsANpu+VQgUT9ZCw2g4sf/ /q7mk8f00DExSooj0kDaGL6RKDHdCJdA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; bh=skmOsCcxFc8JdWNp/ nRHwRHGex6ZV9knrDEapTYEVQk=; b=PLFx66xcea3nhXVlRugHLzV3/lQ+ZlKff iJch8W86VCqHMbLXVKHQHa17+SMJRfqC+JSzibArNSPGZCAg+aIpwphyrtNnNNG6 85TBy42I1h+AnAVmC6obb4bJzt68j+CtjHUgrE0vkQ2GraXtN8ECLk9FjhduzcGT El0wgLaDJZT20pGeaAlEVSMKQ5mb+eU7cGZy96p2JLteH9VFy/VreCZxWIOPEQqy 3Jszn+umqMyVWYEngAKFVpp3k4n8zfgHT9LClHP51zlE/oTf4gwPQWL9lZYPHUop PP3Xg6OBsDmmT13GSQvUshjUeXzuKVmNMrk6M4ZqYFK6VHDR9levQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrjeehgddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepteehheeigfdulefhvedvvddtjeehheekleetkeevgeegudeileeiudeugfef tdejnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgii vghlrdguvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Feb 2022 18:51:58 -0500 (EST) Date: Tue, 15 Feb 2022 15:51:57 -0800 From: Andres Freund To: Heikki Linnakangas Cc: pgsql-hackers Subject: Re: Race conditions in 019_replslot_limit.pl Message-ID: <20220215235157.jknqi73c5scietxe@alap3.anarazel.de> References: <83b46e5f-2a52-86aa-fa6c-8174908174b8@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <83b46e5f-2a52-86aa-fa6c-8174908174b8@iki.fi> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-02-15 23:29:20 +0200, Heikki Linnakangas wrote: > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=desmoxytes&dt=2022-02-14%2006%3A30%3A04 > > [07:42:23] t/018_wal_optimize.pl ................ ok 12403 ms ( 0.00 usr > 0.00 sys + 1.40 cusr 0.63 csys = 2.03 CPU) > # poll_query_until timed out executing this query: > # SELECT wal_status FROM pg_replication_slots WHERE slot_name = 'rep3' > # expecting this output: > # lost > # last actual query output: > # unreserved The relevant bit from the log is: 2022-02-14 07:42:27.817 CET [6209f9d3.68bab:3] LOG: database system is ready to accept read-only connections 2022-02-14 07:42:27.819 CET [6209f9d3.68bb7:1] LOG: started streaming WAL from primary at 0/1B00000 on timeline 1 2022-02-14 07:42:27.819 CET [6209f9d3.68bb7:2] FATAL: could not receive data from WAL stream: ERROR: requested WAL segment 00000001000000000000001B has already been removed 2022-02-14 07:42:27.822 CET [6209f9d3.68bb9:1] LOG: started streaming WAL from primary at 0/1B00000 on timeline 1 2022-02-14 07:42:27.822 CET [6209f9d3.68bb9:2] FATAL: could not receive data from WAL stream: ERROR: requested WAL segment 00000001000000000000001B has already been removed I think what happened is that there was no WAL to receive between the start of the primary and the $node_primary3->wait_for_catchup($node_standby3); Because the slot is created without reserving WAL that allows the primary to remove the WAL segments without ever creating a slot based conflict. I think that should be fixable by reserving the slot at creation time? > and: > > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=serinus&dt=2022-02-15%2011%3A00%3A08 > > # Failed test 'have walsender pid 3682154 > # 3682136' > # at t/019_replslot_limit.pl line 335. > # '3682154 > # 3682136' > # doesn't match '(?^:^[0-9]+$)' > > The latter looks like there are two walsenders active, which confuses the > test. Too bad there's no plain pid in the log_line_prefix. Looks like that used to be the buildfarm default, and I haven't fixed that animals configuration... %c apparently is hex(process startup time).hex(pid) in hex, so we're looking for 382f58... Confirmed by the slot name: 2022-02-15 12:10:20.874 CET [620b8a1c.382f58:5] LOG: received replication command: CREATE_REPLICATION_SLOT "pg_basebackup_3682136" TEMPORARY PHYSICAL ( RESERVE_WAL) which pg_basebackup builds using the backend pid: replication_slot = psprintf("pg_basebackup_%d", (int) PQbackendPID(param->bgconn)); The logs for that pid are: 2022-02-15 12:10:20.873 CET [620b8a1c.382f58:1] LOG: connection received: host=[local] 2022-02-15 12:10:20.874 CET [620b8a1c.382f58:2] LOG: replication connection authorized: user=bf application_name=019_replslot_limit.pl 2022-02-15 12:10:20.874 CET [620b8a1c.382f58:3] LOG: received replication command: SHOW data_directory_mode 2022-02-15 12:10:20.874 CET [620b8a1c.382f58:4] STATEMENT: SHOW data_directory_mode 2022-02-15 12:10:20.874 CET [620b8a1c.382f58:5] LOG: received replication command: CREATE_REPLICATION_SLOT "pg_basebackup_3682136" TEMPORARY PHYSICAL ( RESERVE_WAL) 2022-02-15 12:10:20.874 CET [620b8a1c.382f58:6] STATEMENT: CREATE_REPLICATION_SLOT "pg_basebackup_3682136" TEMPORARY PHYSICAL ( RESERVE_WAL) 2022-02-15 12:10:20.875 CET [620b8a1c.382f58:7] LOG: received replication command: IDENTIFY_SYSTEM 2022-02-15 12:10:20.875 CET [620b8a1c.382f58:8] STATEMENT: IDENTIFY_SYSTEM 2022-02-15 12:10:20.875 CET [620b8a1c.382f58:9] LOG: received replication command: START_REPLICATION SLOT "pg_basebackup_3682136" 0/600000 TIMELINE 1 2022-02-15 12:10:20.875 CET [620b8a1c.382f58:10] STATEMENT: START_REPLICATION SLOT "pg_basebackup_3682136" 0/600000 TIMELINE 1 Even though the node has log_disconnect = true, and other processes indeed log their disconnection, there's no disconnect for the above session until the server is shut down. Even though pg_basebackup clearly finished? Uh, huh? I guess it's conceivable that the backend was still working through process shutdown? But it doesn't seem too likely, given that several other connections manage to get through entire connect / disconnect cycles? > Has anyone looked into these yet? Hadn't yet... Greetings, Andres Freund