From a8d8d06fb345fc0630709a5121242247b01304bb Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 28 Feb 2024 07:14:20 +0000 Subject: [PATCH 1/3] Fix GH-13519: another attempt after the faulty fix. --- ext/pgsql/pgsql.c | 19 +++++++++++++++++-- ext/pgsql/tests/gh13519.phpt | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 ext/pgsql/tests/gh13519.phpt diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 6e04848bdea0b..8f46d90c2c35c 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -559,9 +559,11 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (persistent && PGG(allow_persistent)) { zend_resource *le; + bool update = false; /* try to find if we already have this link in our persistent list */ if ((le = zend_hash_find_ptr(&EG(persistent_list), str.s)) == NULL) { /* we don't */ +newpconn: if (PGG(max_links) != -1 && PGG(num_links) >= PGG(max_links)) { php_error_docref(NULL, E_WARNING, "Cannot create new link. Too many open links (" ZEND_LONG_FMT ")", PGG(num_links)); @@ -587,12 +589,25 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (zend_register_persistent_resource(ZSTR_VAL(str.s), ZSTR_LEN(str.s), pgsql, le_plink) == NULL) { goto err; } - PGG(num_links)++; - PGG(num_persistent)++; + if (!update) { + PGG(num_links)++; + PGG(num_persistent)++; + } } else { /* we do */ if (le->type != le_plink) { goto err; } + if (connect_type & PGSQL_CONNECT_FORCE_NEW) { + PGresult *pg_result; + + while ((pg_result = PQgetResult(le->ptr))) { + PQclear(pg_result); + } + PQfinish(le->ptr); + le->ptr = NULL; + update = true; + goto newpconn; + } /* ensure that the link did not die */ if (PGG(auto_reset_persistent) & 1) { /* need to send & get something from backend to diff --git a/ext/pgsql/tests/gh13519.phpt b/ext/pgsql/tests/gh13519.phpt new file mode 100644 index 0000000000000..17379cdacce71 --- /dev/null +++ b/ext/pgsql/tests/gh13519.phpt @@ -0,0 +1,30 @@ +--TEST-- +GH-13519 - PGSQL_CONNECT_FORCE_NEW with persistent connections. +--EXTENSIONS-- +pgsql +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) From 3753ca14a76a36b43af4127571de10a9ef2aca07 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 28 Feb 2024 07:34:03 +0000 Subject: [PATCH 2/3] disable zts temporarily --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index e08b2539bb70e..a34b524d2c179 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -49,7 +49,7 @@ jobs: - debug: true zts: false - debug: false - zts: true + zts: false name: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}" runs-on: ubuntu-20.04 steps: From fee2dec91fe5ddcf511ffd1d35253222f1d4b44d Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 28 Feb 2024 08:09:01 +0000 Subject: [PATCH 3/3] put back zts --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a34b524d2c179..e08b2539bb70e 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -49,7 +49,7 @@ jobs: - debug: true zts: false - debug: false - zts: false + zts: true name: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}" runs-on: ubuntu-20.04 steps: