Skip to content

Add special handling for unexpected COM_PING packets#5257

Merged
renecannao merged 8 commits intov3.0from
v3.0-handle_unexp_ping
Dec 19, 2025
Merged

Add special handling for unexpected COM_PING packets#5257
renecannao merged 8 commits intov3.0from
v3.0-handle_unexp_ping

Conversation

@JavierJF
Copy link
Collaborator

Description

Implements a workaround for the handling of unexpected 'COM_PING' packets received during query processing, while a resultset is yet being streamed to the client. Received 'COM_PING' packets are queued in the form of a counter. This counter is later used to sent the corresponding number of 'OK' packets to the client after 'MySQL_Session' has finished
processing the current query.

@gemini-code-assist
Copy link

Summary of Changes

Hello @JavierJF, 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 addresses a specific scenario where COM_PING packets are received from a client at an unexpected time, specifically when a MySQL session is in the process of streaming a resultset. The changes implement a temporary mechanism to queue these pings and then send appropriate OK responses to the client once the current query processing is complete. This ensures that the client-server communication flow remains stable and prevents potential client hangs, while also providing new metrics for monitoring this behavior and a dedicated test suite for validation.

Highlights

  • Unexpected COM_PING Handling: Introduced a temporary workaround to correctly handle COM_PING packets received unexpectedly from the client while a resultset is being streamed. These pings are now queued and acknowledged later.
  • Packet Queuing and Acknowledgment: A new unexp_com_pings counter in MySQL_Data_Stream tracks unexpected COM_PING packets. MySQL_Session::RequestEnd now sends an equivalent number of OK packets to the client before the session transitions back to WAITING_CLIENT_DATA.
  • Metrics and Monitoring: Added a new status variable st_var_unexpected_com_ping and a corresponding Prometheus metric proxysql_mysql_unexpected_frontend_com_ping_total to track the occurrence of these unexpected packets.
  • Regression Testing: A new regression test (reg_test_unexp_ping_pkt-t.cpp) has been added to validate the handling of unexpected COM_PING packets across various connection types, including standard, compressed, SSL, and compressed+SSL.
  • Utility Function Improvement: The random_string utility function in test/tap/tap/utils.cpp was refactored to use std::uniform_int_distribution for more robust random string generation.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 introduces a workaround for handling unexpected COM_PING packets from clients. The changes involve queuing these pings and sending back OK packets at the end of a query to prevent client hangs. The implementation is sound, but there's a critical issue in how response packet sequence IDs are handled, which could break client-server communication. Additionally, there are several opportunities for code improvement in the new test files, including simplifying a random string generation function and addressing potential memory leaks and correctness issues in the test logic.

Implements a workaround for the handling of unexpected 'COM_PING'
packets received during query processing, while a resultset is yet being
streamed to the client. Received 'COM_PING' packets are queued in the
form of a counter. This counter is later used to sent the corresponding
number of 'OK' packets to the client after 'MySQL_Session' has finished
processing the current query.
Also fixes 'random_string' utility function for large strings, avoiding
the previous shuffle repetition from the dictionary.
@JavierJF JavierJF force-pushed the v3.0-handle_unexp_ping branch from dfc39aa to 503b097 Compare December 19, 2025 09:38
Logging messages now include 'client address', 'session status' and
'data stream status'. Client address is also logged when OK packets are
dispatched, this should help tracking if a client has received the
expected packets or not.
@JavierJF
Copy link
Collaborator Author

Retest this please.

- Fixed was changing server defaults ('max_allowed_packet') in the same
  connection as the subsequent INSERT.
- Use direct MySQL connection for table/data preparation.
- ProxySQL connection pool required cleanup 'connection_pool' to ensure
  defaults reload.
@JavierJF JavierJF force-pushed the v3.0-handle_unexp_ping branch from 3f8d558 to e73ba2b Compare December 19, 2025 14:08
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@renecannao renecannao merged commit 0b85700 into v3.0 Dec 19, 2025
147 of 154 checks passed
@renecannao renecannao deleted the v3.0-handle_unexp_ping branch March 7, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants