pg_send_query(): Cannot set connection to blocking mode
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
php |
Unknown
|
Unknown
|
|||
php5 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[Impact]
pg_send_query() fails because of an implementation error if connection is done to remote host and query string is long OR transaction is very long. As a result, pg_send_query() is too unstable to be used at all if the connection is made to any other host but 'localhost'.
The problem is caused by the implementation not following the PostgreSQL documentation at http://
"PQflush: [...] After sending any command or data on a nonblocking connection, call PQflush. [...]"
Related PHP Bug: https:/
Patch: https:/
[Test Case]
Test script (from PHP bug):
---
$len = 100000; // This may need to be increased, depending on db server.
$sql = "select 1" . str_repeat(' ', $len - 8);
$con = pg_connect(
pg_send_query($con, $sql);
pg_get_
---
Note that the test script only fails if host is remote (connected using TCP/IP).
[Regression Potential]
Calling PQflush() may cause some additional overhead for the cases where flushing does not need to be done (the cases that happen to work as is). The patch only touches functions pg_send_query() and pg_send_
The documentation of PQflush() says "Attempts to flush any queued output data to the server. Returns 0 if successful (or if the send queue is empty), -1 if it failed for some reason, or 1 if it was unable to send all the data in the send queue yet (this case can only occur if the connection is nonblocking)." Calling PQflush() should be okay for blocking connections, too. In addition, the referenced patch does not even touch that code.
Source: http://
Source: http://<email address hidden>
[Other Info]
ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: php5-pgsql 5.3.10-1ubuntu3.7
ProcVersionSign
Uname: Linux 3.8.0-27-generic x86_64
ApportVersion: 2.0.1-0ubuntu17.4
Architecture: amd64
Date: Wed Sep 4 15:22:25 2013
InstallationMedia: Ubuntu 12.04.1 LTS "Precise Pangolin" - Release amd64 (20120823.1)
MarkForUpload: True
SourcePackage: php5
UpgradeStatus: No upgrade log present (probably fresh install)
description: | updated |
Thank you for taking the time to report this bug and helping to make Ubuntu better.
It looks like the current development version already has this issue fixed, so I'm marking this bug as Fix Released. I verified this by manually checking the ext/pgsql/pgsql.c file in the source against the patch provided.
It looks like upstream have not backported this fix into their 5.3 branch. But the patch seems trivial enough that we could backport it easily enough in order to fix 12.04, if we were to choose to do this.
So if you need a fix for an existing stable release, please comment with a justification against https:/ /wiki.ubuntu. com/StableRelea seUpdates# When and complete steps 1 through 4 in https:/ /wiki.ubuntu. com/StableRelea seUpdates# Procedure - and go ahead with all the steps if you can. Note that that SRU team would need to make a final decision.
I have one concern about any possible backport. The patch does not test the connection to make sure that it is non-blocking. Will calling PQflush on a blocking connection cause any issues here? Or is the connection only ever going to be non-blocking due to the way the existing code works?