Skip to content
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

server: compare packet length with variable max_allowed_packet #32216

Closed
wants to merge 3 commits into from

Conversation

unconsolable
Copy link
Contributor

Signed-off-by: unconsolable [email protected]

What problem does this PR solve?

Issue Number: close #31422 #32164

Problem Summary:

Session variable max_allowed_packet seems not taking effect

What is changed and how it works?

  • According to https://dev.mysql.com/doc/refman/8.0/en/packet-too-large.html, packet length is compared with session variable max_allowed_packet before dispatch. If packet is too large, corresponding error is returned and connection is closed.
  • It is a bit hard to write an UT for it, so a manual test is chosen instead as follows.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    set @@net_buffer_length=1024;
    set @@max_allowed_packet=1024;
    SELECT length("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") as len;
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Session variable `max_allowed_packet` will take effect and compare with packet length

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added needs-cherry-pick-release-5.0 needs-cherry-pick-release-5.1 release-note Denotes a PR that will be considered when it comes time to generate release notes. needs-cherry-pick-release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 9, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Feb 9, 2022

@@ -1082,6 +1082,19 @@ func (cc *clientConn) Run(ctx context.Context) {
disconnectByClientWithError.Inc()
return
}
// get max allowed packet length and compare
Copy link
Contributor

@Defined2014 Defined2014 Feb 10, 2022

Choose a reason for hiding this comment

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

Could you add a test, like an IT test?

Copy link
Contributor Author

@unconsolable unconsolable Feb 10, 2022

Choose a reason for hiding this comment

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

I tried to add an IT in explaintest in commit 102032d, but it failed in test new_character_set as follows https://ci.pingcap.net/blue/organizations/jenkins/tidb_ghpr_check/detail/tidb_ghpr_check/49418/pipeline. So I revert it.

logutil.Logger(ctx).Error("parse max allowed packet error", zap.Error(err))
return
}
if uint64(len(data)) > maxAllowedPacket {
Copy link
Contributor

Choose a reason for hiding this comment

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

The data maybe not only contain one packet, see the code below.

tidb/server/packetio.go

Lines 128 to 139 in cb8e65a

for {
buf, err := p.readOnePacket()
if err != nil {
return nil, errors.Trace(err)
}
data = append(data, buf...)
if len(buf) < mysql.MaxPayloadLen {
break
}
}

And the scope of max_allowed_packet in TiDB also have some problems.
In MySQL

mysql> set @@max_allowed_packet=default;
ERROR 1621 (HY000): SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A communication packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a replication source server to a replica.

So I think the packet of readOnePacket is different from the communication packet, but I'm not that sure. We'd better wait on others' opinion.

  • The scope does has some problem, but I think we'd better leave for another issue.

Signed-off-by: unconsolable <[email protected]>
Signed-off-by: unconsolable <[email protected]>
@unconsolable
Copy link
Contributor Author

I think it is not a suitable fix, as it only compare the packet length, without reducing buffer allocation according to max_allowed_packet, so it will be closed.

@unconsolable unconsolable deleted the issue-31422 branch February 24, 2022 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 needs-cherry-pick-release-5.1 needs-cherry-pick-release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

max_allowed_packet length is set to 1024 but its not working for string length.
4 participants