cancel any active async query on persistent connection retirement
authorMichael Wallner <mike@php.net>
Fri, 8 Feb 2013 22:09:31 +0000 (23:09 +0100)
committerMichael Wallner <mike@php.net>
Fri, 8 Feb 2013 22:09:31 +0000 (23:09 +0100)
src/php_pq.c

index 6223ef95c74f90a47194102be28773dbe6be1006..64d59af36d06f8f417fc6e33bf2ad986616981b4 100644 (file)
@@ -1810,6 +1810,7 @@ static void php_pqconn_notice_ignore(void *p, const PGresult *res)
 static void php_pqconn_retire(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC)
 {
        php_pqconn_event_data_t *evdata = PQinstanceData(*handle, php_pqconn_event);
+       PGcancel *cancel;
        PGresult *res;
 
        /* go away */
@@ -1818,6 +1819,11 @@ static void php_pqconn_retire(php_persistent_handle_factory_t *f, void **handle
        /* ignore notices */
        PQsetNoticeReceiver(*handle, php_pqconn_notice_ignore, NULL);
 
+       /* cancel async queries */
+       if (PQisBusy(*handle) && (cancel = PQgetCancel(*handle))) {
+               PQcancel(cancel, ZEND_STRL("retiring persistent connection"));
+               PQfreeCancel(cancel);
+       }
        /* clean up async results */
        while ((res = PQgetResult(*handle))) {
                PHP_PQclear(res);