Skip to content

Conversation

@Gonlo2
Copy link

@Gonlo2 Gonlo2 commented Sep 2, 2025

This PR avoid sending an unencrypted message to a server that uses SSL, as this will cause the backend to abruptly close the connection.

A clear description of the issue

It seems that since the standard MySQL function is blocking, this logic has been recoded in ProxySQL to use a non blocking aproach, at least partially because it doesn't allow SSL or compression. This causes the MySQL backend to receive an incorrect message (or rather, an invalid message since it is not encrypted) and MySQL abruptly cuts the connection. This is not a serious problem since the desired result is achieved in the end, but it makes it difficult to detect real network problems since the MySQL metrics constantly show that there are problems.

Not sending anything can be worse than sending something, but it works for us, and I don't know if it works for you too.

ProxySQL version

v3.0.2

The steps to reproduce the issue

Anything that attempts to close a backend connection if SSL is used can be seen in the MySQL errors defining log_error_verbosity=3 or with the global status metric aborted_clients.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @Gonlo2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where ProxySQL's custom connection closing mechanism would send unencrypted QUIT messages to MySQL backends configured with SSL. This behavior caused MySQL to abruptly terminate connections, leading to an increase in aborted_clients metrics and obscuring actual network problems. The changes introduce a conditional check to prevent these unencrypted messages from being sent when SSL is in use, thereby improving the accuracy of monitoring metrics and preventing unnecessary connection resets.

Highlights

  • Issue Resolution: Prevents sending unencrypted close messages to SSL-enabled MySQL backends, which previously caused abrupt connection terminations.
  • Metric Accuracy: Addresses the problem of aborted_clients metrics being inflated due to these erroneous connection closures, improving the clarity of monitoring data.
  • Conditional Logic: Modifies connection closing functions in MySQL_Monitor.cpp and mysql_connection.cpp to conditionally send the QUIT command only when SSL is not in use.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly prevents sending an unencrypted COM_QUIT packet over an SSL connection by adding a check for !my->options.use_ssl in close_mysql functions. This avoids abrupt connection closures from the MySQL backend. My review suggests a small improvement to also check for connection compression. This would make the fix more complete, especially in lib/mysql_connection.cpp where a FIXME comment explicitly mentions that both encryption and compression are not supported by the custom close_mysql logic.


static void close_mysql(MYSQL *my) {
if (my->net.pvio) {
if (my->net.pvio && !my->options.use_ssl) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly avoids sending an unencrypted COM_QUIT packet over an SSL connection. To make this more robust, you could also check if compression is enabled, as sending an uncompressed packet on a compressed connection would also be incorrect. This would be consistent with a similar FIXME comment in lib/mysql_connection.cpp.

	if (my->net.pvio && !my->options.use_ssl && !my->options.compress) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the comment that it does not work with compression this change would be fine but, since I have not tested it, I did not want to introduce it. If you can check it and it solves this issue, I see no problem in extending the patch.

// FIXME: currently doesn't support encryption and compression
void MySQL_Connection::close_mysql() {
if ((send_quit) && (mysql->net.pvio) && ret_mysql) {
if ((send_quit) && (mysql->net.pvio) && ret_mysql && !mysql->options.use_ssl) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly avoids sending an unencrypted COM_QUIT packet over an SSL connection, which addresses part of the FIXME on line 2959. To further address the FIXME, you could also add a check to prevent sending an uncompressed packet when compression is enabled.

	if ((send_quit) && (mysql->net.pvio) && ret_mysql && !mysql->options.use_ssl && !mysql->options.compress) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the comment that it does not work with compression this change would be fine but, since I have not tested it, I did not want to introduce it. If you can check it and it solves this issue, I see no problem in extending the patch.

@renecannao
Copy link
Contributor

Can one of the admins verify this patch?

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 2, 2025

@noizu noizu added the status/triage Mark issue for team triage label Sep 30, 2025
@noizu
Copy link
Collaborator

noizu commented Oct 14, 2025

@renecannao please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/triage Mark issue for team triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants