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 1wfwJL-005nti-0V for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 09:05:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfwJJ-00A3vk-3B for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 09:05:17 +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.96) (envelope-from ) id 1wfwJJ-00A3vb-2G for pgsql-hackers@lists.postgresql.org; Sat, 04 Jul 2026 09:05:17 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wfwJH-00000001R9L-30pP for pgsql-hackers@postgresql.org; Sat, 04 Jul 2026 09:05:16 +0000 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-381ed661712so765445a91.2 for ; Sat, 04 Jul 2026 02:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783155914; cv=none; d=google.com; s=arc-20260327; b=rTvEqN70yq9HaDo3SCRKZS2Zt7dhN9/EiyTUtM1JHikX/+K/frRRsnMOxFOihBVvYD qTcBwiCSps5R5BsrCTiW2DbXnsZbcW9TagzlleFO3gwBDT97SGJhFoivD24yXnbb0v0e NqKjSLkO32HPOle71k8iCHKh6B0+v14RuR088QQ6bAQSPd8vaF6VeAdg/2jdhZHuvpQQ KVmPL5N27Wu8uQTvR/7ORbTIVKosP10/ObFGXvebWkPlKXC/ZPcOXMNpiw8noCfpPKRo ZmDmcxeMIW9uqpoUFo3Hf5MaoxJy6ASY1firzL+BVnJXXwJPnXn8WrlanImtszaY0m4k xToQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OD1Fp9VDFnlnn9pEXulod3V/G7SvYXrIrQ1I/SN6w9Q=; fh=dQM0siywClKgUX3Bl/tkrUIOvgdwl3mPzWNo5UER168=; b=cnPgeo6n068wDiMM/cgg6HtvZHYPC5YAH2f5RWAYx3GDDryc3RYY6myAnyj0njzccV JRRj8P3nB2cnC4Xa6cwK5g6amJ03IMAz6SFyswwb/viMqBU4ggUQ0tClmP6kKfyklHV3 yzkmXAO0qCXU6gwwZMas63zYVZTENoTEh2S5yNOOUpPyqEQQ4KqyRAWktMad9uHNQNrL EsX/GGMLZf2OdHXlP9YdEQZywbOs6qedRthmCUa69z3jYqoGZPjA/uyQOKQQ7tOn/9bR I8BY9m+wjE3g8ULqOSUwW6BfomwZ+mNeKbafXGsegpWNOcRvi2ZnGSZurarl4qAmltIP HNQg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783155914; x=1783760714; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OD1Fp9VDFnlnn9pEXulod3V/G7SvYXrIrQ1I/SN6w9Q=; b=ZDbYprN4ylKz75CBpYz+5jVj8/pAGexAoFFbHibO7hE1wD4SyzZ3HOETNHlx3txspY Lua27FFH4k3iS5lIp8mFqnesIds6aC7hvZScY4yjZMCJK3w9vsvI32/b3CFMAnM2XXAM X/qAT5V+kj7kD2jyYaLVYd7K6dYYc70f1466hHEnDK/vvqHeh5TsgpbigL80E4kGw07j /huRzshPFaNPTvFbcEVw2Tm7qpQECwPn8h3OmevNf0d2bjT0Ww77/t8LyXJGqhgCtkcF 1iKpq63ttU5hZmvACs++PjsS4T0nMK4JYGQETAMgfcMssqCDHRl1OO9ZjtVsLT4K00fa YG2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783155914; x=1783760714; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OD1Fp9VDFnlnn9pEXulod3V/G7SvYXrIrQ1I/SN6w9Q=; b=WFwHAcUW3qep+urMdGOncM+bII9q5jV2sQQ/vrbV9alJ2q1w+W7D5LnAIfQEmhDHgc N6GxM0Ez2jqHkczXwM/qSJ0b3rD27tbiaGSh1a22bpQRsIvYa4mzLzAQnHxhe6o3iq8F rc4IetejWHd58s3K8OlIUn79ARiNowgv/l2+vbfKNW5UdpElI3H3ca0rz7nxwjpjSmwn QrhXpIKPyvp0Vr5bo/m1D9N/LM66PZN/h9l79ireNxpSLOatoRAor0KByc50XHEU2heB c09cJSZ6ceJ4uU5rKVuxTmAZkdOkwjbAbkHCCJSoVWNUlcx15ZsQHT4loMsql8qr7+Mt RTaA== X-Gm-Message-State: AOJu0Yywntr9D3plg0fcKJtjLWcoCsYuY/V4DL/GuVhppfekfCCK+cEv l8QDieOx+jjxbjumq0VZQNvY3Avns2DjxZJihrZ9kEFxlS+VMiwy4tj2PjfeKqN8+SkdvBeeok5 t71J49FgLJNC8+7CZ6WcUdeTSejpH25c= X-Gm-Gg: AfdE7cmldN3Ez3ZBhmtH54R7xBnkf2NvHmE1i3QzkYaW+/f1jKuxA56aghBx0ecl84d i08WohzZonMXjhu4KZeb/yVuLDR40oclVX7brXHYceiYh9IxT5JnL610/Dqu8XCK3//WdS1drsR Fi/Gk5ynS01gCYWgzjed34tSpC+mqT3j5ML5EAqKz/UgQrJ1KeGm0zjZ6XHHqGeOK/8Zesna4sa zmElk8vHQs0QKGBEq5LlvSmbrTnGz68XMlL6yNzCpBF824u0TaeVr2ZnVlVexUNIw8wt0y+Eldc QNjIhd7OZAj3HLj3L1+HzDp/MER8aE67qlDdiZa/eplTKcfNI/GSkp1jIaa00cL1vzzewbrFNqp Ze/kJMWHntB9qPDUxbumlSrn3DMmOZA== X-Received: by 2002:a17:90b:5103:b0:381:1fd3:e4ef with SMTP id 98e67ed59e1d1-3829f4f0d4emr2631363a91.25.1783155913785; Sat, 04 Jul 2026 02:05:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Etsuro Fujita Date: Sat, 4 Jul 2026 18:04:59 +0900 X-Gm-Features: AVVi8Cc1bLcjWuri2RCbI6wq-XvGVtdg5mSGeO2MIUiy74sVCLKmJN9sHjgJLCA Message-ID: Subject: Re: Bug in asynchronous Append To: Alexander Korotkov Cc: pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Alexander, On Sat, Jul 4, 2026 at 7:00=E2=80=AFAM Alexander Korotkov wrote: > ExecReScanAppend() unconditionally resets callback_pending for all AsyncR= equests. The problem is that postgres_fdw keeps its own knowledge for the = same fact: PgFdwConnState.pendingAreq =E2=80=93 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+u= sermapping pair). The blind reset in nodeAppend.c only touches the local As= yncRequest.callback_pending; it never touches PgFdwConnState.pendingAreq, w= hich correctly points to the still-dangling request. > > Later, when another partition sharing that same connection gets its own R= eScan (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 f= irst 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); > > =E2=80=93 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 ExecAppendAsyncBegi= n(). ExecAppendAsyncBegin() performs this cleanup along with ExecReScan(),= which completes the async fetch. Interesting! Thanks for the report and patch! Will review. Best regards, Etsuro Fujita