Bug #111172 X protocol does not report "too many connections"
Submitted: 28 May 2023 4:19 Modified: 29 May 2023 12:14
Reporter: Geert Vanderkelen Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Document Store: X Plugin Severity:S3 (Non-critical)
Version:8.0.32, 8.0.36 OS:Any
Assigned to: CPU Architecture:Any
Tags: Error 1040, X Plugin

[28 May 2023 4:19] Geert Vanderkelen
Description:
When ysing the X Protocol, and setting `mysqlx_max_connections` to something very low, connections run out, and the X Protocol Client will get an EOF from the server.

This is in contrast with the Classic Protocol, where the MySQL server correctly reports an 1040 "Too many connections".

I faced this problem while debugging another issue using my own Connector using X Protocol written in Go. The source for that is included in "How to repeat".

How to repeat:
mysql> set GLOBAL mysqlx_max_connections = 1;
mysql> set GLOBAL max_connections = 1;

# Using non-root user
# this will work
sh> mysqlsh scott:tiger@127.0.0.1:33060/
# this will fail (since first connection is still open)
sh> mysqlsh scott:tiger@127.0.0.1:33060/

# error message is
ArgumentError: X protocol error: MySQL server has gone away
Classic protocol error: MySQL Error 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

#
# Classic Protocol
#
# open a few, then error would happen:
sh> mysqlsh scott:tiger@127.0.0.1:3306/

MySQL Error 1040 (HY000): Too many connections

Suggested fix:
It would be great if we X Protocol could handle the error that user has reached her limit, just as the Classic Protocol does. Now I cannot tell the user what is wrong and need to report a generic "bad connection". The "server has gone away" is infamously bad.

Can we check in the Plugin the stats and then report an error? If I connect with a wrong password, I also get an error back, this is very similar.
[28 May 2023 5:38] Geert Vanderkelen
Looking at the source, and trying to find a way to fix this, I can see that lots of errors are simply logged but not returned to the client, just closing the connection. That's not nice.

In X plugin client.cc, you'll find:

  } catch (std::exception &e) {
    log_error(ER_XPLUGIN_FORCE_STOP_CLIENT, client_id(), e.what());
  }

But Client::run returns void.

There are ways to returns the error, since some things are indeed reported back.
[29 May 2023 12:14] MySQL Verification Team
Hello Geert,

Thank you for the report and feedback.

Regards,
Umesh