php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31411 Misplaced "Cannot set connection to blocking mode" at end of output
Submitted: 2005-01-04 22:39 UTC Modified: 2005-07-14 01:00 UTC
Votes:35
Avg. Score:4.6 ± 0.6
Reproduced:30 of 31 (96.8%)
Same Version:9 (30.0%)
Same OS:13 (43.3%)
From: mike at ecommerce dot com Assigned:
Status: No Feedback Package: PostgreSQL related
PHP Version: 5CVS, 4CVS (2005-01-17) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mike at ecommerce dot com
New email:
PHP Version: OS:

 

 [2005-01-04 22:39 UTC] mike at ecommerce dot com
Description:
------------
Problem Description:
I have an issue with a functionality in the function _rollback_transactions defined in ext/pgsql/pgsql.c. This function is responsible to rollback all transaction that are currently open in persistent database connections, so those transactions do not leak over to following scripts.

Before it sends any commands over the connection, it does the following:

if (PQ_SETNONBLOCKING(link, 0)) {
    php_error_docref("ref.pgsql" TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
    return -1;
}

When this "Cannot set connection to blocking mode" error is raised, then in almost all cases it is because the connection to the database server is broken, maybe because the PostgreSQL server was restarted, or the network connection to it broke.

The problem is not the error message, because if something is wrong with the database connection, it is correct to print an error (or to call the error handler).

The problem is that in this special case this error message is not displayed in the script that opened the database connection, but rather in the first script this is run after the persistent connection broke. This can be a script that is executed sometime afterwards - maybe a long time afterwards, maybe in a script that never opened a database connection. Basically it could occur in scripts that would normally not cause an error at all. My point is that cause and effect of the error are disconnected.

Real-Life example:
The company i work for has this problem currently in one of our applications. We use persistent connections to a PostgreSQL database over an unreliable internet connection, that breaks every now and then. Normally, this is not a big deal, because we have local database caches which is used as a failsafe solution, and all scripts are programmed in a way to watch out for database errors and automatically re-connect to this failsafe database without the user noticing a thing. All fine until now.

But every time the internet connection - and therefore the connection to the remote database - breaks, all other PHP applications that are hosted on the same server, which do use different databases or do not use a database at all, suddenly print the message "Notice: (null)(): Cannot set connection to blocking mode in Unknown on line 0" at the end of the output.

Suggested Resolution:
Remove the line that calls php_error_docref to raise the error. The database link is removed anyway from the list of persistent connections, due to the "return -1;" directly afterwards.

I am aware that there are other solutions, like adjusting "error_reporting" not to include E_NOTICE, or to turn off "display_errors". Or to install a custom error handler that silently ignores this error.

However, after carefully considering all options, IMHO i think that removing the line in the PHP sources that raises the error is the cleanest solution, with the main argument for it being that cause and effect of the problem do not directly relate. That means the script that prints the error and/or handles the error in its custom error handler may have nothing to do with the broken database connection.


Actual result:
--------------
Notice: (null)(): Cannot set connection to blocking mode in Unknown on line 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-12 07:13 UTC] yohgaki at ohgaki dot net
The best way to fix this problem is "hendle broken persistent connections w/o errors in pgsql module".  For the time being, I suggest to use @ operator or define your error handler so that the error is ignored.
 [2005-01-18 09:35 UTC] yohgaki at ohgaki dot net
I've forgot I've implemented auto persistent connection reset feature.

Try to change following ini setting to On.
----
; Detect broken persistent links always with pg_pconnect().
; Auto reset feature requires a little overheads.
pgsql.auto_reset_persistent = Off
----
 [2005-01-18 12:20 UTC] mike at ecommerce dot com
No, i am afraid, setting pgsql.auto_reset_persistent = On doesn't change anything.

Looking at the code in ext/pgsql/pgsql.c, this setting is only used in pg_connect, but has no influence in the function in question, _rollback_transactions.
 [2005-04-11 09:28 UTC] exaton at free dot fr
I believe I might be experiencing something similar. Setup is PHP 5.0.4 on Apache 2.0.53 under WinXP SP2.

I've just upgraded to PG 8.0.2. With PG 8.0.1, I had to use persistent connections to my (also local) database, otherwise the connection time was absolutely prohibitive. The PG team have apparently solved this issue, so I've dropped persistence as it was cluttering up my system unnecessarily.

So now with PG 8.0.2, I'm getting "PHP Notice:  Unknown: Cannot set connection to blocking mode in Unknown on line 0" at the end of PHP output, _sporadically_. Not systematically, rather when the page hasn't been reloaded in a little while (3-4 minutes can suffice).

It's not messing up the page apart from the notice output ; the rest of the SQL in my scripts works just fine.
 [2005-07-06 13:06 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-07-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-11-19 21:18 UTC] ctrix at hotmail dot com
Same problem here with PHP 5.2.0.
It's easily reproduceable: simply start a persistent connection, then restart postgres.

That message will appear.
 [2008-08-21 07:41 UTC] igor dot kotsarev at gloru dot net
Same problem on PHP 5.26
 [2008-11-06 17:59 UTC] benjiro at benjiro dot com
This problem has also confirmed in PHP Version 5.2.6-2+b1.

Recreate:

Run your test script with a permanent connection.
Restart postgresql for whatever reason.
Enjoy this nice "NOTICE on 06-11 18:58 with response pg_query_params() [function.pg-query-params]: Cannot set connection to blocking mode".

Also note: Don't forget to clear your browser cache afterward, or else your going to keep getting this message when you refresh a page ( F5 ). Making it worse then it is.
 [2009-02-20 18:23 UTC] wmoran at potentialtech dot com
I can reproduce this on both PHP 5.2.6 and 5.2.8 using PostgreSQL 8.3.6 client/server on FreeBSD 6.3

Further, the error reporting is odd.  No setting of error_reporting in my php.ini seems to squelch it.
 [2009-11-13 18:03 UTC] manuel dot garciah at ife dot org dot mx
Hi, We are using PHP 5.1.6 with PostgrSQL 8.1.11, and we obtained the next message:
http://bugs.php.net/captcha-image.php?x=1258135348&
Notice: pg_exec() [function.pg-exec]: Cannot set connection to blocking mode in
/home/httpd/shtml/sg/derfe/funciones.inc on line 730

Notice: Unknown: Cannot set connection to blocking mode in Unknown on line 0

We use pg_pconnect, What do you suggest to use? or exist some versi?n in PHP where this bug was solved?
 [2010-10-04 16:56 UTC] wmoran at potentialtech dot com
I can no longer reproduce this problem on PHP 5.3.3 running on FreeBSD 8.1 against PostgreSQL 8.4.4.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Aug 09 09:01:24 2020 UTC