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.96) (envelope-from ) id 1wgkfn-006NFX-1E for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:51:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgkfm-001H7C-0O for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:51:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wgkfl-001H73-2D for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 14:51:49 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wgkfj-000000024eD-0qwt for pgsql-hackers@postgresql.org; Mon, 06 Jul 2026 14:51:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1783349505; bh=bJPCf7fZzm8qRW2Tt07VfdKIA8yk8Sdda1lcJ+VqfxQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=e21rCPTg69D7va5L7Xis40d/AL8ALkay6k25877xrxOP75AFrbwEioNODF57yN+gW 8hk0wxujimCnXGShDkKF31tShkUB5L7HsrHX4bFa7+7roF8Gyfn9XpEf6psGcYxTyC 1WxEybQVAzUxpC3jn8bQNx3kYlTdw5jze5fXutO3rYt8qKM+6nYGg1WWRt2y/1IZbv alrWCCKHswjcBGj0mF7mf4EA9nEk0o/ywkNwhvEPd/xg2TiireOnqdJ6yONUszBhlz zFqUusnVBzFLcNymI/oW642AJI4wTd5WiNzbecp2OS5yN3cm/mxHkuAymOqRSjz//m Jy4l56lVxYmSA== Received: from mail.l.postgrespro.ru (webmail-master-mstn.l.postgrespro.ru [192.168.2.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.pyhalov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 971405FE21; Mon, 6 Jul 2026 17:51:45 +0300 (MSK) MIME-Version: 1.0 Date: Mon, 06 Jul 2026 17:51:45 +0300 From: Alexander Pyhalov To: Alexander Korotkov Cc: pgsql-hackers Subject: Re: Bug in asynchronous Append In-Reply-To: References: Message-ID: X-Sender: a.pyhalov@postgrespro.ru Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 3.0.0.9059, bases: 2026/07/06 13:00:00 #28400771 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander Korotkov писал(а) 2026-07-04 01:00: > Hi! > > ExecReScanAppend() unconditionally resets callback_pending for all > AsyncRequests. The problem is that postgres_fdw keeps its own > knowledge for the same fact: PgFdwConnState.pendingAreq – a pointer > to "pending async request" for a given connection. That connection > can be shared by several partitions/foreign tables (postgres_fdw > caches one connection per server+usermapping pair). The blind reset in > nodeAppend.c only touches the local AsyncRequest.callback_pending; it > never touches PgFdwConnState.pendingAreq, which correctly points to > the still-dangling request. > > Later, when another partition sharing that same connection gets its > own ReScan (for instance, its chgParam changed because of the LATERAL > parameter, and it already has a cursor open), it sends "CLOSE cursor" > via pgfdw_exec_query(). Before sending any new command on the > connection, that function first drains whatever request is still > outstanding on it: > > if (state && state->pendingAreq) > process_pending_request(state->pendingAreq); > > And process_pending_request() starts with: > > Assert(areq->callback_pending); > > – which fails, because the flag was corrupted some rounds earlier. > > The attached patch contains both the reproduction case and the fix. > The fix postpones the reset of the callback_pending flag to > ExecAppendAsyncBegin(). ExecAppendAsyncBegin() performs this cleanup > along with ExecReScan(), which completes the async fetch. > Hi. The analysis seems correct to me as well as fix. -- Best regards, Alexander Pyhalov, Postgres Professional