Repository navigation
Conversation
The poll callback completed an operation as soon as it had a result, also while libpq was still busy with the rest of the reply. An error can follow a result: a statement on its own is committed after its result is sent, so a deferred constraint or trigger may still refuse it. That error was then discarded by the next send, and the refused write was reported as successful. The callback now keeps the results across reads and completes the operation once pg_get_result() has returned false. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pgsql handle can report a write the server refused as successful.
Cause
The poll callback completes an operation with whatever results it can read without blocking, even while
pg_connection_busy()is still true. A statement on its own is committed after its result is sent, so a deferred constraint or deferred trigger can still refuse it. When that error arrives in a later read, the operation has already completed with the successful result, and the nextsend()discards the error in its drain loop.Reproduce
With PHP 8.5 and PostgreSQL 15, up to 3 of the 6667 inserts returned successfully on 2.x. With this change none did, in repeated runs. It depends on how the reply is split, so the new test makes it deterministic: a deferred trigger raises a notice (which sends the result to the client), sleeps, then raises an exception.
Fix
The results are kept across reads, and the operation completes only once
pg_get_result()has returnedfalse.Not covered
UnhandledFutureError. Fixing it meansPqHandleholding the connection until the last result, which is a larger change.COPYis unchanged. While looking at this loop I noticed that on 2.xCOPY (SELECT 1) TO STDOUTkeeps collecting results until PHP runs out of memory, as libpq returns theCOPYresult repeatedly. That is the same before and after this change.Tests
The suite passes locally on the
eventandstream_selectdrivers, and Psalm and php-cs-fixer report nothing new. With theevdriver the pgsql tests are skipped or fail on the existing pecl-ev check, as on 2.x.🤖 Generated with Claude Code