Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sCH2P-004RiG-Tt for pgsql-hackers@arkaria.postgresql.org; Wed, 29 May 2024 11:00:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sCH2P-00ElR6-2R for pgsql-hackers@arkaria.postgresql.org; Wed, 29 May 2024 11:00:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sCH2O-00ElQo-IH for pgsql-hackers@lists.postgresql.org; Wed, 29 May 2024 11:00:08 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sCH2K-002Vb5-8C for pgsql-hackers@postgresql.org; Wed, 29 May 2024 11:00:07 +0000 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2e72b8931caso19648081fa.0 for ; Wed, 29 May 2024 04:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716980402; x=1717585202; darn=postgresql.org; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=91oLTHEZyUthLbB+tSdYxphCjGy3fncEtLIUGKl2kMc=; b=i+wFUe1CXP7pyy9U3jPUp6J1Rej5r+4JjrWPCHWPWeACFH7cP6To5Am/3jxhzqUWtn kayAiZypMhx0dTYlt04vLacUJARFHOZtGFoQplTL8oExqkYaGhEFeTyr8zVPzdSuYqq/ mRDIElcuyLK21hGC19nBIEcURgYZOAn3OxXwHl4HQ3tDkZiilPd05a3qICvGI7MWROkv ZZbfAF2UJNVhXikM5XdX1aecGhHh7JZR2oqU+f3ugJPunWQmjKGrWYVilDyBSIOggTZ3 yxloOL8rae9f1pt2PKZKWGIlSDbs10vCqCxvyzFsFuT6z2j6i34lH0yc8tNjXPXnkd0k I7qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716980402; x=1717585202; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=91oLTHEZyUthLbB+tSdYxphCjGy3fncEtLIUGKl2kMc=; b=dmWG6SLqySoaxIUlndu+FrGTNvEKOrgURwPJafb9ZJtpaTPNjN8fys9mX7g/DMK6Q1 g0IqOW0yp6IvNvZ/Yn9ubqDaX0psgtrQkms8yi+2PB5e9DSpe+Mtjib03JLk4mBTUN6A cEKC5GmjWvlBs5cHYKqD4p+glmuQOaZ6MpQmG+Fgnj+LOwl1wySNl7HJWF3hlGpBrvTa KQqIcbPJVMRANddBmFlk0dFJu9IP83aYK0r6chrzvZcUX4O/5xYHrkVbECPyf2W+6INi Ou/z0XmnveGdCTK1j2nHusJFpH/v9ha6YKhluxPbzjuDNIWX3Qswi4aSm/K5OOfIHDV4 G6Xw== X-Gm-Message-State: AOJu0Yxb1QyFPtFbVIMXnoEy0hjUQ75SsCZZ0MFRcAcVhMJa9Dk8ZdMR pJXqtViylCSu2HCkX5EfmHaNZ/SVD2VvjmfndKvTF8o9rXQGtd0rh637kg== X-Google-Smtp-Source: AGHT+IGJ/rOW/4F/ud1pf5ba53XHM1ScUY60ik2KJ1pr/9DlPVXb7GPv3NDRX1Z2ejqJdiHbQN3+EQ== X-Received: by 2002:a2e:9f43:0:b0:2d8:8eb4:11a6 with SMTP id 38308e7fff4ca-2e95b08c1b7mr87129921fa.12.1716980402323; Wed, 29 May 2024 04:00:02 -0700 (PDT) Received: from [1.0.0.7] ([81.23.166.29]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2e95bcc820fsm25063591fa.4.2024.05.29.04.00.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 May 2024 04:00:01 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------PVwN0cJ0Xx5GEsnbMLeWYxGu" Message-ID: Date: Wed, 29 May 2024 14:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Content-Language: en-US From: Alexander Lakhin Subject: 001_rep_changes.pl fails due to publisher stuck on shutdown To: pgsql-hackers List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------PVwN0cJ0Xx5GEsnbMLeWYxGu Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello hackers, As a recent buildfarm test failure [1] shows: [14:33:02.374](0.333s) ok 23 - update works with dropped subscriber column ### Stopping node "publisher" using mode fast # Running: pg_ctl -D /home/bf/bf-build/adder/HEAD/pgsql.build/testrun/subscription/001_rep_changes/data/t_001_rep_changes_publisher_data/pgdata -m fast stop waiting for server to shut down.. ... ... ... .. failed pg_ctl: server does not shut down # pg_ctl stop failed: 256 # Postmaster PID for node "publisher" is 2222549 [14:39:04.375](362.001s) Bail out!  pg_ctl stop failed 001_rep_changes_publisher.log 2024-05-16 14:33:02.907 UTC [2238704][client backend][4/22:0] LOG: statement: DELETE FROM tab_rep 2024-05-16 14:33:02.925 UTC [2238704][client backend][:0] LOG: disconnection: session time: 0:00:00.078 user=bf database=postgres host=[local] 2024-05-16 14:33:02.939 UTC [2222549][postmaster][:0] LOG:  received fast shutdown request 2024-05-16 14:33:03.000 UTC [2222549][postmaster][:0] LOG:  aborting any active transactions 2024-05-16 14:33:03.049 UTC [2222549][postmaster][:0] LOG: background worker "logical replication launcher" (PID 2223110) exited with exit code 1 2024-05-16 14:33:03.062 UTC [2222901][checkpointer][:0] LOG: shutting down 2024-05-16 14:39:04.377 UTC [2222549][postmaster][:0] LOG:  received immediate shutdown request 2024-05-16 14:39:04.382 UTC [2222549][postmaster][:0] LOG:  database system is shut down the publisher node may hang on stopping. I reproduced the failure (with aggressive autovacuum) locally and discovered that it happens because: 1) checkpointer calls WalSndInitStopping() (which sends  PROCSIG_WALSND_INIT_STOPPING to walsender), and then spins inside  WalSndWaitStopping() indefinitely, because: 2) walsender receives the signal, sets got_STOPPING = true, but can't exit WalSndLoop(): 3) it never sets got_SIGUSR2 (to get into WalSndDone()) in  XLogSendLogical(): 4) it never sets WalSndCaughtUp to true: 5) logical_decoding_ctx->reader->EndRecPtr can't reach flushPtr in  XLogSendLogical(): 6) EndRecPtr doesn't advance in XLogNextRecord(): 7) XLogDecodeNextRecord() fails do decode a record that crosses a page  boundary: 8) ReadPageInternal() (commented "Wait for the next page to become  available") constantly returns XLREAD_FAIL: 9) state->routine.page_read()/logical_read_xlog_page() constantly returns  -1: 10) flushptr = WalSndWaitForWal() stops advancing, because  got_STOPPING == true (see 2). That is, walsender doesn't let itself to catch up, if it gets the stop signal when it's lagging behind and decoding a record requires reading the next wal page. Please look at the reproducing test (based on 001_rep_changes.pl) attached. If fails for me as below: # 17 Bailout called.  Further testing stopped:  pg_ctl stop failed FAILED--Further testing stopped: pg_ctl stop failed make: *** [Makefile:21: check] Ошибка 255 [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=adder&dt=2024-05-16%2014%3A22%3A38 [2] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=dikkop&dt=2024-04-24%2014%3A38%3A35 (apparently the same) Best regards, Alexander --------------PVwN0cJ0Xx5GEsnbMLeWYxGu Content-Type: application/x-perl; name="099_walsender_stop.pl" Content-Disposition: attachment; filename="099_walsender_stop.pl" Content-Transfer-Encoding: 7bit # Copyright (c) 2021-2024, PostgreSQL Global Development Group # Basic logical replication test use strict; use warnings FATAL => 'all'; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; use Test::More; # Initialize publisher node my $node_publisher = PostgreSQL::Test::Cluster->new('publisher'); $node_publisher->init(allows_streaming => 'logical'); $node_publisher->append_conf('postgresql.conf', qq{ autovacuum_naptime = 1 autovacuum_vacuum_threshold = 1 }); $node_publisher->start; # Create subscriber node my $node_subscriber = PostgreSQL::Test::Cluster->new('subscriber'); $node_subscriber->init; $node_subscriber->start; # Create some preexisting content on publisher $node_publisher->safe_psql('postgres', "CREATE TABLE tab_rep (a int primary key)"); # Setup structure on subscriber $node_subscriber->safe_psql('postgres', "CREATE TABLE tab_rep (a int primary key)"); # Setup logical replication my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; $node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub"); $node_publisher->safe_psql('postgres', "ALTER PUBLICATION tap_pub ADD TABLE tab_rep"); $node_subscriber->safe_psql('postgres', "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub" ); # Wait for initial table sync to finish $node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub'); for (my $i = 1; $i <= 100; $i++) { $node_publisher->wait_for_catchup('tap_sub'); diag("$i"); $node_publisher->safe_psql('postgres', "INSERT INTO tab_rep SELECT generate_series(1, (random() * 40000)::integer) "); $node_publisher->safe_psql('postgres', "DELETE FROM tab_rep"); $node_publisher->stop('fast'); $node_publisher->start(); } ok(1); done_testing(); --------------PVwN0cJ0Xx5GEsnbMLeWYxGu--