Req #79134 [NEW]: Add non-blocking way to close pg conn - pg_cancel_query() can take a long time

From: Date: Thu, 16 Jan 2020 16:58:10 +0000
Subject: Req #79134 [NEW]: Add non-blocking way to close pg conn - pg_cancel_query() can take a long time
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224940@lists.php.net to get a copy of this message
From: tandre Operating system: Any PHP version: Irrelevant Package: PDO PgSQL Bug Type: Feature/Change Request Bug description:Add non-blocking way to close pg conn - pg_cancel_query() can take a long time Description: ------------ When a Postgres server is under high CPU load, pg_cancel_query can take a long time, causing issues for the application. (I'm also using pgbouncer, but it's probably not relevant) 1. pg_cancel_query() has no asynchronous version. It may be convenient to add pg_cancel_query_async() - that way, PHP applications can do other work and asynchronously wait for the connection to close using stream_socket_select() and pg_socket() using the async capabilities mentioned in https://grokbase.com/t/php/php-internals/141d5nb7a2/non-blocking-postgresql. - If the query (e.g. SELECT * FROM MY_TABLE) is unintentionally the cause of the high load, it'd make sense to send a message to cancel it before closing the connection. 2. It's currently possible to stop the current connection without waiting for results by calling pg_connection_reset(). However, if the server is having issues, then the side effect of reconnecting is counterproductive. It may be useful to also add pg_connection_terminate() to stop the connection with PQfinish(), without calling PQgetResult(). Right now, the available ways of cancelling requests I can find all call PQgetResult(), which will block waiting for the result of any in-progress queries for much more than 10 seconds when the Postgres server is under high load. ``` static void _close_pgsql_link(zend_resource *rsrc) { PGconn *link = (PGconn *)rsrc->ptr; PGresult *res; zval *hash; while ((res = PQgetResult(link))) { PQclear(res); } PQfinish(link); ``` Expected result: ---------------- There should be a way for the client to cancel and close in-progress postgres queries with a bounded timeout, in cases when the Postgres server is under high load and slow to respond. -- Edit bug report at https://bugs.php.net/bug.php?id=79134&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79134&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79134&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79134&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79134&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79134&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79134&r=support Expected behavior: https://bugs.php.net/fix.php?id=79134&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79134&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79134&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79134&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79134&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79134&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79134&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79134&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79134&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79134&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79134&r=mysqlcfg

« previous php.bugs (#224940) next »