diff --git a/NEWS b/NEWS index 81095b5f96b..1a099ff0e20 100644 --- a/NEWS +++ b/NEWS @@ -123,6 +123,7 @@ PHP NEWS . pg_fetch_object raises a ValueError instead of an Exception. (David Carlier) . Added GH-9344, pipeline mode support. (David Carlier) + . pg_cancel use thread safe PQcancel api instead. (David Carlier) - Phar: . Fix memory leak in phar_rename_archive(). (stkeke) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 56b828df7f5..9eab2342002 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -3470,12 +3470,22 @@ static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type) PQconsumeInput(pgsql); RETVAL_LONG(PQisBusy(pgsql)); break; - case PHP_PG_ASYNC_REQUEST_CANCEL: - RETVAL_LONG(PQrequestCancel(pgsql)); + case PHP_PG_ASYNC_REQUEST_CANCEL: { + PGcancel *c; + char err[256]; + int rc; + + c = PQgetCancel(pgsql); + RETVAL_LONG((rc = PQcancel(c, err, sizeof(err)))); + if (rc < 0) { + zend_error(E_WARNING, "cannot cancel the query: %s", err); + } while ((pgsql_result = PQgetResult(pgsql))) { PQclear(pgsql_result); } + PQfreeCancel(c); break; + } EMPTY_SWITCH_DEFAULT_CASE() } if (PQsetnonblocking(pgsql, 0)) {