Re:Re: Bypassing cursors in postgres_fdw to enable parallel plans

Yilin Zhang <jiezhilove@126.com>

From: "Yilin Zhang" <jiezhilove@126.com>
To: "Rafia Sabih" <rafia.pghackers@gmail.com>
Cc: "Robert Haas" <robertmhaas@gmail.com>, "KENAN YILMAZ" <kenan.yilmaz@localus.com.tr>, "Andy Fan" <zhihuifan1213@163.com>, "PostgreSQL Hackers" <pgsql-hackers@lists.postgresql.org>
Date: 2026-07-02T07:02:37Z
Lists: pgsql-hackers
At 2026-06-29 17:27:17,"Rafia Sabih" <rafia.pghackers@gmail.com>  wrote  :


>I understand your concern and I tried to solve it by passing fsstate now,
>also saving a backpointer to the node in active_fsstate to solve the issue
>with make_tuple_from_result_row. Since we need to have conn from fsstate, I
>am not sure how we can do that if we have only active_fsstate passed to the
>function.


I have reviewed all your previous patch revisions and tested the v12 patch.
You have fixed the issue raised by Robert where active_scan was not cleared when it ought to have been.
However, in my opinion, active_scan is cleared prematurely before the drain loop finishes executing.
If an error occurs mid-drain (such as query cancellation), the connection remains in an in-flight query state with no active_scan referencing it.
In the subsequent postgresEndForeignScan, is_active_scan() will return false, so pgfdw_cancel_scan() will never be invoked.
In subsequent queries, conn_state->active_scan may become a dangling pointer, triggering a crash.
I have written a test case that reproduces this crash to confirm the bug.










Best regards,

--

Yilin Zhang