Bug #98624 | Can't connect to MySQL after establishing around 65536 connections | ||
---|---|---|---|
Submitted: | 16 Feb 2020 16:02 | Modified: | 12 Mar 2020 1:38 |
Reporter: | Fungo Wang (OCA) | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Connection Handling | Severity: | S3 (Non-critical) |
Version: | 8.0.19 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | 1130, 65536, Connections, lf_hash, mdl |
[16 Feb 2020 16:02]
Fungo Wang
[16 Feb 2020 16:08]
Fungo Wang
65536 is a huge number, it takes time to setup so many connections, and maybe you also need to increase your OS limits config to support creating so many connections (when thread pool is not used). To make life easier, you can apply below diff to 8.0.19 code, and rebuild. After changing the LF_PINBOX_MAX_PINS to 128, in my test, 124 connections is enougth to repro. diff --git a/mysys/lf_alloc-pin.cc b/mysys/lf_alloc-pin.cc index 02d6c36..5532ff2 100644 --- a/mysys/lf_alloc-pin.cc +++ b/mysys/lf_alloc-pin.cc @@ -127,7 +127,7 @@ static_assert(sizeof(std::atomic<void *>) == sizeof(void *), #include "mysql/service_mysql_alloc.h" #include "mysys/mysys_priv.h" /* key_memory_lf_node */ -#define LF_PINBOX_MAX_PINS 65536 +#define LF_PINBOX_MAX_PINS 128 static void lf_pinbox_real_free(LF_PINS *pins); That's why in the previous post's gdb stack, pins == 137 will cause failure. ``` (gdb) p pins $2 = 137 // here LF_PINBOX_MAX_PINS = 128 ```
[17 Feb 2020 13:41]
MySQL Verification Team
Hi Mr. Wang, Thank you for your bug report. First of all, this could be an error that is specific on the OS, which you have not specified. It could be a bug about the error that is reported. Simply, it could be a problem that you have run out of the file handles. So, try increasing those and try again, please ...... Thanks in advance.
[17 Feb 2020 13:56]
Fungo Wang
Hi Sinisa, Have you tried the repro steps, or checked my analysis? I'm pretty sure that the limitations of my OS resources are not reached, cause I have enlarged them to big enough values. And actually the 1130 error is not related to OS resource, if you analyze the mysql code, only one place can report 1130, that is in `check_connection()` caused by failing `acl_check_host()`. Please try the repro, thanks very much!
[17 Feb 2020 16:53]
MySQL Verification Team
Hi, I did not manage to repeat the behaviour with a shell script, due to the shell limits. However, I managed to repeat the behaviour with a program written in C. I also found a culprit of this limit of the total number of connections. It is this line: #define LF_PINBOX_MAX_PINS 65536 However, I can't tell whether this limit can be raised or not. Development shall have to decide upon that. Verified as reported.
[18 Feb 2020 0:33]
Fungo Wang
Hi Sinisa, Thanks for your verification. Just want to make it more clear. This is a bug in the MDL subsystem, the scalability of MDL is limited to 65536 users, due to the pins number limitation (LF_PINBOX_MAX_PINS = 65536) of the LF_HASH it employs. After 64K users, MDL subsystem will fail to work. The exposed behavior in 8.0 is 1130 ERROR, a connection failure, because `acl_check_host()` make the very first request to MDL subsytem for each THD, this because worklog "WL#9045: Make user management DDLs atomic", in which the acl cache lock implementation is change from OS mutex to a MDL LOCK, whose key is ACL_CACHE. As long as lf_hash is used by MDL, this limitations exists, it behavior differently in 5.7 (I'll report a separate bug later), but the root cause is same. Thanks.
[18 Feb 2020 13:27]
MySQL Verification Team
HI Mr. Wang, You are welcome and thanks for the additional comments.
[21 Feb 2020 8:44]
Ståle Deraas
Posted by developer: There is also a TCP restriction around 65K on the number of open tcp connections to single port.
[12 Mar 2020 1:38]
Fungo Wang
Hi Ståle Deraas, > There is also a TCP restriction around 65K on the number of open tcp connections to single port. There is no such 64K socket limitation that a linux tcp port can handle, you could easily set up more than 64K socket to a mysql-sever:3306 using several client boxes. Pls also check my reply under my new bug #98911. Thanks.