Skip to content

Commit 40383d3

Browse files
committed
ext/pgsql: pg_cancel_query internal update.
Removing (obsolete) PGrequestCancel usage in favor of the thread-safe PQcancel/PQfreeCancel pair.
1 parent f4ede23 commit 40383d3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

ext/pgsql/pgsql.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,12 +3470,29 @@ static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
34703470
PQconsumeInput(pgsql);
34713471
RETVAL_LONG(PQisBusy(pgsql));
34723472
break;
3473-
case PHP_PG_ASYNC_REQUEST_CANCEL:
3474-
RETVAL_LONG(PQrequestCancel(pgsql));
3473+
case PHP_PG_ASYNC_REQUEST_CANCEL: {
3474+
PGcancel *c;
3475+
char err[256];
3476+
int rc;
3477+
3478+
c = PQgetCancel(pgsql);
3479+
3480+
if (!c) {
3481+
// only possible reason since the connection is already verified at that point
3482+
zend_error(E_WARNING, "can't allocate a cancel procedure");
3483+
RETURN_FALSE;
3484+
}
3485+
3486+
RETVAL_LONG((rc = PQcancel(c, err, sizeof(err))));
3487+
if (rc < 0) {
3488+
zend_error(E_WARNING, "can't cancel the query: %s", err);
3489+
}
34753490
while ((pgsql_result = PQgetResult(pgsql))) {
34763491
PQclear(pgsql_result);
34773492
}
3493+
PQfreeCancel(c);
34783494
break;
3495+
}
34793496
EMPTY_SWITCH_DEFAULT_CASE()
34803497
}
34813498
if (PQsetnonblocking(pgsql, 0)) {

0 commit comments

Comments
 (0)