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 1s07Qz-0013v1-3T for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Apr 2024 22:19:16 +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 1s07Px-003QWE-9Y for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Apr 2024 22:18:14 +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 1s07Px-003QW5-19 for pgsql-bugs@lists.postgresql.org; Thu, 25 Apr 2024 22:18:13 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s07Pv-0003Bp-1N for pgsql-bugs@lists.postgresql.org; Thu, 25 Apr 2024 22:18:12 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4VQVbz1Nhlz49Pyk; Fri, 26 Apr 2024 01:18:07 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1714083487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OhGIj5NpP76yRnriZdzABbreNSjTo1KH6SAQzgzfnWs=; b=RVecc6Fb3lrcawGg9LjTRuqPU20UL38fqUqgodL2X1INOGMjIb59/GRsR+ry1cFGL5CDm7 zflT1DL2d3MGbhFqjdm8009iQWbQwUlIUpZtSMc8tnTb6EPOgYb0WsZHtog1Y7w2t+zrHv Q10ytJCtNykFIyIPHjEXHxyHjwGziNKeKjj7xbkOJhOt6wZC64LojThLVj/vkXsbU5VmCo bEjZQ/tQpWjHwc5QY0xRkT/PLk6smGEjsaHkm1mhuQOma/BddYNpEvuuQ1eZ3FkbDvj8lP kk06KlFnyN3MYk7q4hUfjYs4gaeM211+m75mgPNZGouXuARzATNALq9valRaow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1714083487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OhGIj5NpP76yRnriZdzABbreNSjTo1KH6SAQzgzfnWs=; b=gQGBj2dWxfK7mOAllfmPuRoXH1OfuC/RpGbDqgvy/TIlqSkj+9Zulb6kUyKIPzQ4lz+X3j 31Ac9eHHUlfThcjD6AM2S9WF+jGNhctqZxdENUX50FI88gUiMNY6Spw6452+MfwnBAPzyh XKuHKqgMLje//++oIp09zCiCNLtQtNYjSGNnwfZ7UuC3lnKGqfLUSnDS5OqkSMPq92ac07 bfUKntSLX26DHXEjTKeN6qCZ1jrOrnbWctrka4gcqhX/34IQ1yMJgWv7x7n+HXiBO0YjL4 lA5LZ1gbgWW6/WX37kIntCExhb5DrR9NWtT8kztvwdow7tT8qL1e+79+M+2IRA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1714083487; a=rsa-sha256; cv=none; b=mjVPhSeYpQaeVWKkIKV42zDxnUBCzwsWt0dADavZIP9QlaISl+tjy21hXsa6/kJ/eAYaPZ wWv9z9ZX8u8jsyn7nqukz6qhWyy2Xz9+h64rkf3JB5G86IP3MdjIqHW+dckmAzwJe+ZWg0 HCiVjfayYT15pIBzgj9eYzR0/xyOTklklDUUZc8bpghyKBMR7Ig704RYTHsnFepplsv6/U qX1tVcv7ez7D2lXcGHoFtqKjDqq6Hp8v2FRjisnQrp8Oo3t0q2MqdVqI0HDKaouMKI73Qq 6zg8/cFAGJkoLsxSqh2O14jnpTyDMCIYt496m8VZhYQnapP0C/e5W/FonOvHqg== Message-ID: <30909ba9-7a97-4ee0-b86d-3c75b1acf77e@iki.fi> Date: Fri, 26 Apr 2024 01:18:06 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #17690: Nonresponsive client on replica can halt replication indefinitely To: jacob.baskin@gmail.com, pgsql-bugs@lists.postgresql.org References: <17690-d4f1a1944550b801@postgresql.org> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <17690-d4f1a1944550b801@postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sorry for the very late response, I happened to notice this just now while browsing for bugs that got no answers. On 18/11/2022 21:21, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 17690 > Logged by: Jacob Baskin > Email address: jacob.baskin@gmail.com > PostgreSQL version: 13.0 > Operating system: Linux (CentOS 7) > Description: > > We have discovered that a badly-behaved client connected to a database hot > replica can indefinitely block replication from progressing. The client's > back-end gets into a state where it does not stop when the recovery process > tries to cancel conflicting queries, as long as there is still pending data > to be written. > > To trigger this, the client needs to be: > - Actively running a query which conflicts with recovery > - Not reading data from its socket about query results (e.g., run "select * > from large_table" in psql and then Ctrl-Z as results are being streamed) > > We believe this failure mode is deterministic. This bug definitely affects > postgres 13, and we believe it is still present in HEAD. We are running > Linux (Centos 7). > > The sequence of events is as follows: > > 1. Postmaster tries to kill a connection that conflicts with recovery > (standby.c:393) > 2. The connection process gets SIGUSR1. > 3. This invokes RecoveryConflictInterrupt, which sets QueryCancelPending, > but NOT (generally) ProcDiePending (postgres.c:3039) > 4. The connection process repeatedly processes ProcessClientWriteInterrupt, > which will handle interrupts if ProcDiePending is set but not otherwise > (postgres.c:526) Yes, I concur that's a problem. > We believe the appropriate fix is to check for RecoveryConflictPending in > addition to ProcDiePending on postgres.c:526. > > This fix would be a one-line patch which we are happy to submit but first > want to make sure that this is the correct approach. That makes sense at quick glance, although you need to be careful to not mess with the protocol state by erroring out in the middle of writing a message to the socket. There is some protection against that, see PqCommBusy in pqcomm.c, but I'm not sure if it can get the connection to a sane state if you error out from ProcessClientWriteInterrupt. That's not a problem for ProcDiePending because the connection is being killed anyway, but with a recovery conflict you only want to cancel the running query. -- Heikki Linnakangas Neon (https://neon.tech)