Skip to content

[1.9] fix PING on compressed connections #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

methane
Copy link
Member

@methane methane commented Jun 12, 2025

Add missing mc.syncSequence()

Fix #1718

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

Copy link

coderabbitai bot commented Jun 12, 2025

Walkthrough

The changes revise the handling and synchronization of packet and compression sequence numbers in the MySQL driver. Adjustments are made to ensure correct tracking and updating of sequence numbers for both compressed and uncompressed packets, with improved logging and synchronization after packet operations. Debug output formatting is also standardized.

Changes

Files Change Summary
compress.go Switched from using sequence to compressSequence for compression packet tracking; improved debug output formatting.
packets.go Unified sequence number checking and updating logic; moved sequence reset and synchronization to after packet writes; improved error and debug logging; adjusted command packet writing and long data handling.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant mysqlConn
    participant compIO

    App->>mysqlConn: Ping/Query
    mysqlConn->>compIO: writeCompressedPacket()/writePacket()
    compIO->>mysqlConn: syncSequence()
    mysqlConn->>compIO: readCompressedPacket()/readPacket()
    compIO->>mysqlConn: update compressSequence/sequence
    mysqlConn->>App: Return result/error
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct handling of packet and compression sequence numbers after Ping with compress=true (#1718)
Ensure subsequent queries after Ping with compression enabled return correct results (#1718)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested labels

bug


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dfd973a and 1883773.

📒 Files selected for processing (2)
  • compress.go (2 hunks)
  • packets.go (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packets.go (1)
errors.go (1)
  • ErrPktSyncMul (29-29)
🔇 Additional comments (5)
compress.go (1)

116-120: LGTM! Proper compression sequence tracking

The changes correctly implement independent tracking of compression sequence numbers, with appropriate warning logging for mismatches while maintaining compatibility with MySQL/MariaDB client behavior.

packets.go (4)

66-79: Well-structured sequence number validation

The consolidated sequence checking logic properly differentiates between compressed and uncompressed connections, maintaining compatibility with MySQL/MariaDB behavior while ensuring data integrity for uncompressed multi-packet reads.


144-144: Good practice: Debug output redirected to stderr

Redirecting debug output to stderr is the correct approach, keeping stdout clean for actual program output.


443-445: Critical fix: Sequence synchronization after command packets

These changes add the missing syncSequence() calls that are essential for maintaining proper sequence numbers on compressed connections. This directly addresses the PING issue described in #1718.

Also applies to: 486-488


969-970: Correct sequence reset timing for COM_LONG_DATA packets

Moving the sequence reset inside the loop ensures proper sequence handling for each COM_LONG_DATA packet, as per the MySQL protocol specification.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coveralls
Copy link

Coverage Status

coverage: 82.906% (-0.004%) from 82.91%
when pulling 1883773 on methane:fix-ping-1.9
into dfd973a on go-sql-driver:1.9.

@methane
Copy link
Member Author

methane commented Jun 13, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Jun 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@methane methane added the bug label Jun 13, 2025
@methane methane enabled auto-merge (squash) June 13, 2025 01:54
@methane methane disabled auto-merge June 13, 2025 01:56
@methane methane merged commit 324cbb3 into go-sql-driver:1.9 Jun 13, 2025
36 checks passed
@methane methane deleted the fix-ping-1.9 branch June 13, 2025 01:56
hantang pushed a commit to qundao/mirror-forgejo that referenced this pull request Jun 14, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) | require | patch | `v1.9.2` -> `v1.9.3` |

---

### Release Notes

<details>
<summary>go-sql-driver/mysql (github.com/go-sql-driver/mysql)</summary>

### [`v1.9.3`](https://github.com/go-sql-driver/mysql/releases/tag/v1.9.3)

[Compare Source](go-sql-driver/mysql@v1.9.2...v1.9.3)

#### What's Changed

-   \[1.9] test stability improvement. by [@&#8203;methane](https://github.com/methane) in go-sql-driver/mysql#1699
-   \[1.9] Transaction Commit/Rollback returns conn's cached error by [@&#8203;methane](https://github.com/methane) in go-sql-driver/mysql#1702
-   backport benchmark_test by [@&#8203;methane](https://github.com/methane) in go-sql-driver/mysql#1706
-   \[1.9] optimize readPacket ([#&#8203;1705](go-sql-driver/mysql#1705)) by [@&#8203;methane](https://github.com/methane) in go-sql-driver/mysql#1707
-   \[1.9] fix PING on compressed connections by [@&#8203;methane](https://github.com/methane) in go-sql-driver/mysql#1723
-   release v1.9.3 by [@&#8203;methane](https://github.com/methane) in go-sql-driver/mysql#1725

**Full Changelog**: go-sql-driver/mysql@v1.9.2...v1.9.3

</details>

---

### Configuration

📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC40OC40IiwidXBkYXRlZEluVmVyIjoiNDAuNDguNCIsInRhcmdldEJyYW5jaCI6ImZvcmdlam8iLCJsYWJlbHMiOlsiZGVwZW5kZW5jeS11cGdyYWRlIiwidGVzdC9ub3QtbmVlZGVkIl19-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8186
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants