Skip to content

Handle MySQL 8.0 AuthSwitchRequest during authentication#5

Merged
kerryjiang merged 11 commits intomasterfrom
copilot/fix-mysqlconnection-authentication-bug
Feb 7, 2026
Merged

Handle MySQL 8.0 AuthSwitchRequest during authentication#5
kerryjiang merged 11 commits intomasterfrom
copilot/fix-mysqlconnection-authentication-bug

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

MySQL 8.0 defaults to caching_sha2_password. When our client requests mysql_native_password, the server sends an AuthSwitchRequest (0xFE header) which was incorrectly treated as an EOF packet, causing all integration tests to fail with "Unknown command or packet type. (Error 1047)".

Changes

Protocol handling

  • Add AuthSwitchRequestPacket to decode plugin name and auth data from switch requests
  • Add AuthSwitchResponsePacket to encode auth response for switched plugin
  • Update MySQLPacketDecoder to distinguish AuthSwitchRequest from EOF during handshake (AuthSwitch has >4 bytes payload)
  • Handle auth switch loop in MySQLConnection.ConnectAsync()
  • Strip trailing null byte from salt (MySQL sends 20-byte salt + null terminator)

CI configuration

  • Use MySQL Docker service container with MYSQL_ROOT_PASSWORD environment variable for reliable root password setup
  • Configure MySQL root user with mysql_native_password authentication plugin
  • Update test host from localhost to 127.0.0.1 for Docker compatibility
services:
  mysql:
    image: mysql:8.0
    env:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - 3306:3306

Tests

  • Remove MySQL availability skip checks (MySQL should always be available for integration tests)
  • Accept both "authentication failed" and "unsupported authentication plugin" as valid auth failure messages

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ted to true

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug in MySQLConnection authentication logic Fix EOF packet incorrectly marking authentication as successful Feb 7, 2026
Copilot AI requested a review from kerryjiang February 7, 2026 04:47
Copilot AI and others added 2 commits February 7, 2026 04:54
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
… comment

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Copilot AI changed the title Fix EOF packet incorrectly marking authentication as successful Fix EOF packet auth bug and skip integration tests when MySQL unavailable Feb 7, 2026
Copilot AI and others added 2 commits February 7, 2026 05:16
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
…aching_sha2

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Copilot AI changed the title Fix EOF packet auth bug and skip integration tests when MySQL unavailable Handle MySQL 8.0 AuthSwitchRequest during authentication Feb 7, 2026
/// Checks if MySQL server is available for integration tests.
/// The result is cached after the first check.
/// </summary>
public static bool IsMySQLAvailable
Copy link
Member

Choose a reason for hiding this comment

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

we should remove the MySQL Availability tool, since MySQL should be available when we run integration tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the MySQL availability check tool from TestConst.cs in 4deddb1.

[Trait("Category", "Integration")]
public async Task ConnectAsync_WithValidCredentials_ShouldAuthenticateSuccessfully()
{
if (!TestConst.IsMySQLAvailable)
Copy link
Member

Choose a reason for hiding this comment

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

remove all this kind of checks, since we can always ensure mysql server is available if we want to run integration tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed all MySQL availability checks from MainTest.cs and other test files in 4deddb1.

Copilot AI and others added 2 commits February 7, 2026 05:29
…available for integration tests

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 7, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid-host-that-does-not-exist
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/SuperSocket.MySQL.Test.runtimeconfig.json --depsfile /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/SuperSocket.MySQL.Test.deps.json /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/testhost.dll --port 34975 --endpoint 127.0.0.1:034975 --role client --parentprocessid 4135 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/SuperSocket.MySQL.Test.runtimeconfig.json --depsfile /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/SuperSocket.MySQL.Test.deps.json /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/testhost.dll --port 44301 --endpoint 127.0.0.1:044301 --role client --parentprocessid 4399 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/SuperSocket.MySQL.Test.runtimeconfig.json --depsfile /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/SuperSocket.MySQL.Test.deps.json /home/REDACTED/work/SuperSocket.MySQL/SuperSocket.MySQL/tests/SuperSocket.MySQL.Test/bin/Debug/net9.0/testhost.dll --port 34369 --endpoint 127.0.0.1:034369 --role client --parentprocessid 4721 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from kerryjiang February 7, 2026 05:32
@kerryjiang kerryjiang marked this pull request as ready for review February 7, 2026 05:33
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
cp tests/SuperSocket.MySQL.Test/mysql.cnf ~/.my.cnf
sudo systemctl start mysql.service
mysql -V
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; FLUSH PRIVILEGES;"
Copy link
Member

Choose a reason for hiding this comment

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

I got the error "ERROR 1045 (28000): Access denied for user 'runner'@'localhost' (using password: NO)" from this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e541db7 by using sudo mysql instead of mysql. On Ubuntu, the root MySQL user uses auth_socket by default, so sudo mysql can connect without credentials while mysql as the runner user cannot.

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
cp tests/SuperSocket.MySQL.Test/mysql.cnf ~/.my.cnf
sudo systemctl start mysql.service
mysql -V
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; FLUSH PRIVILEGES;"
Copy link
Member

Choose a reason for hiding this comment

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

I got the error "ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)" right now. Can we set auth type for root from ENV?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in db4462f by switching to a MySQL Docker service container. This uses MYSQL_ROOT_PASSWORD: root env var to set the password directly, avoiding the auth_socket issues with Ubuntu's pre-installed MySQL. Also changed TestConst.Host to 127.0.0.1 for Docker compatibility.

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Copilot AI requested a review from kerryjiang February 7, 2026 06:00
@kerryjiang kerryjiang merged commit f214991 into master Feb 7, 2026
1 check passed
@kerryjiang kerryjiang deleted the copilot/fix-mysqlconnection-authentication-bug branch February 7, 2026 06:05
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