php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81155 Mysql close is NOT synchronous
Submitted: 2021-06-17 14:35 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: video dot ice dot power at seznam dot cz Assigned:
Status: Open Package: PDO MySQL
PHP Version: 8.0.7 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: video dot ice dot power at seznam dot cz
New email:
PHP Version: OS:

 

 [2021-06-17 14:35 UTC] video dot ice dot power at seznam dot cz
Description:
------------
Mysql close is NOT synchronous - it does NOT wait until the connection is closed/released by the database server which causes more simultaneous connections than needed from a script than connect/disconnect from the same database often.

An example of such usecase is unit testing.

I have tested also PostgreSQL. This PDO driver handles close synchronously/ok (SQL to limit connections: ALTER ROLE user CONNECTION LIMIT 1).

MySQL driver needs to be fixed as even server limit of 2 is not enough, currently limit of like 5 is needed even if there is no more than 1 simultaneous client connection.

Test script:
---------------
# 1. limit connection limit to 1
php -r '(new PDO("mysql:host=mysql", "user", "pass"))->exec("ALTER USER '"'"'user'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 1");'

# 2. connect/disconnect often
for ($i = 0; $i < 10000; $i++) {
    (new PDO("mysql:host=mysql", "user", "pass"))->exec("SELECT 1");
}

Expected result:
----------------
no error

Actual result:
--------------
connection limit is exhausted about every 1000th connection

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 09 00:03:37 2021 UTC