Skip to content

ext/pdo_pgsql: Fix the connection state left behind by a lazy fetch - #23065

Draft
KentarouTakeda wants to merge 1 commit into
php:PHP-8.5from
KentarouTakeda:pdo-pgsql-lazy-fetch-drain
Draft

ext/pdo_pgsql: Fix the connection state left behind by a lazy fetch#23065
KentarouTakeda wants to merge 1 commit into
php:PHP-8.5from
KentarouTakeda:pdo-pgsql-lazy-fetch-drain

Conversation

@KentarouTakeda

@KentarouTakeda KentarouTakeda commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

With ATTR_EMULATE_PREPARES or ATTR_DISABLE_PREPARES, a lazy fetch (PDO::ATTR_PREFETCH => 0) left the connection busy once it ended, so the next one failed with SQLSTATE[HY000]: another command is already in progress. The cleanup drains the rest of the result set only while the statement is flagged as streaming, and both callers cleared that flag before calling it; let the cleanup clear it itself.

Such a statement also never cleared the connection's pointer to itself, so destroying it left the connection pointing at freed memory for the next lazy fetch to read. Clear the pointer when the statement is destroyed, unless the connection object is gone too.

Independently of how it was prepared, a statement whose stream was taken over by another kept its row counters after its result was freed, so fetch() returned a row of NULLs instead of false. Check the result before trusting the counters.

@KentarouTakeda
KentarouTakeda force-pushed the pdo-pgsql-lazy-fetch-drain branch from 1f18350 to df8d70e Compare August 5, 2026 16:13
@KentarouTakeda KentarouTakeda changed the title ext/pdo_pgsql: Drain the connection when a lazy fetch ends ext/pdo_pgsql: Fix the connection state left behind by a lazy fetch Aug 5, 2026
@KentarouTakeda
KentarouTakeda force-pushed the pdo-pgsql-lazy-fetch-drain branch 2 times, most recently from 1019743 to a698573 Compare August 5, 2026 16:24
@KentarouTakeda
KentarouTakeda force-pushed the pdo-pgsql-lazy-fetch-drain branch from a698573 to 1a30f7e Compare August 5, 2026 16:28
@KentarouTakeda

Copy link
Copy Markdown
Contributor Author

Converting to draft: the drain loop this restores can hang when the statement left the connection in a COPY state. I will update once that is sorted out.

@KentarouTakeda
KentarouTakeda marked this pull request as draft August 5, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant