zim32 / mysql.dart

MySQL client for Dart written in Dart
BSD 3-Clause "New" or "Revised" License
67 stars 18 forks source link

MySQLProtocolException: Unsupported generic packet: [2, 0, 0, 2, 1, 3] #29

Closed wustrong closed 2 years ago

wustrong commented 2 years ago

I created MySQLConnectionPool, when execute with ('select 1'), it returned what title shows.

what does that mean,and how to fix it?

zim32 commented 2 years ago

Hello. Can you write your setup. Where is dart code. Where is mysql server? What version of mysql server?

zim32 commented 2 years ago

This are several issues related to this error, but I can not reproduce it..

MHShetty commented 2 years ago

Here are some logs from the latest logging branch for this issue:

Launching lib\main.dart on Windows in debug mode...
Building Windows application...
Debug service listening on ws://127.0.0.1:50248/PnzuRO6Gvvo=/ws
Syncing files to device Windows...
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection.createConnection (package:mysql_client/src/mysql_client/connection.dart:83:12)
flutter: │ #1   init (package:test_project/sql.dart:11:39)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Establishing socket connection
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: Isconnected: false
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection.createConnection (package:mysql_client/src/mysql_client/connection.dart:85:12)
flutter: │ #1   <asynchronous suspension>
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Socket connection established
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:163:12)
flutter: │ #1   MySQLConnection.connect.<anonymous closure> (package:mysql_client/src/mysql_client/connection.dart:123:17)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Processing socket data. Current state is _MySQLConnectionState.waitInitialHandshake
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processInitialHandshake (package:mysql_client/src/mysql_client/connection.dart:280:12)
flutter: │ #1   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:167:13)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Processing initial handshake
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: Buffer: [10, 56, 46, 48, 46, 50, 57, 0, 46, 0, 0, 0, 122, 102, 2, 50, 8, 12, 71, 23, 0, 255, 255, 255, 2, 0, 255, 223, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 26, 52, 106, 107, 49, 116, 17, 9, 70, 111, 13, 0, 99, 97, 99, 104, 105, 110, 103, 95, 115, 104, 97, 50, 95, 112, 97, 115, 115, 119, 111, 114, 100, 0]
flutter: byteData: TypedDataView(cid: 152)
flutter: protocolVersion: 10
flutter: serverVersion: 8.0.29
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processInitialHandshake (package:mysql_client/src/mysql_client/connection.dart:289:12)
flutter: │ #1   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:167:13)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 MySQLPacketInitialHandshake:
flutter: │ 🐛 
flutter: │ 🐛 authPluginDataPart1: [122, 102, 2, 50, 8, 12, 71, 23],
flutter: │ 🐛 authPluginDataPart2: [17, 26, 52, 106, 107, 49, 116, 17, 9, 70, 111, 13, 0],
flutter: │ 🐛 authPluginName: caching_sha2_password,
flutter: │ 🐛 capabilityFlags: 3758096383,
flutter: │ 🐛 charset: 255,
flutter: │ 🐛 connectionID: 46,
flutter: │ 🐛 protocolVersion: 10,
flutter: │ 🐛 serverVersion: 8.0.29,
flutter: │ 🐛 statusFlags: [2, 0]
flutter: │ 🐛 
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processInitialHandshake.initiateSSL (package:mysql_client/src/mysql_client/connection.dart:294:16)
flutter: │ #1   MySQLConnection._processInitialHandshake.initiateSSL (package:mysql_client/src/mysql_client/connection.dart:293:31)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Initiating SSL connection
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processInitialHandshake.initiateSSL (package:mysql_client/src/mysql_client/connection.dart:316:16)
flutter: │ #1   <asynchronous suspension>
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 SSL connection established
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processInitialHandshake (package:mysql_client/src/mysql_client/connection.dart:337:12)
flutter: │ #1   <asynchronous suspension>
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Auth plugin name is: caching_sha2_password
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processInitialHandshake (package:mysql_client/src/mysql_client/connection.dart:381:16)
flutter: │ #1   <asynchronous suspension>
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Caching sha2 password response send
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:163:12)
flutter: │ #1   MySQLConnection._processInitialHandshake.initiateSSL.<anonymous closure> (package:mysql_client/src/mysql_client/connection.dart:323:13)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Processing socket data. Current state is _MySQLConnectionState.initialHandshakeResponseSend
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:212:16)
flutter: │ #1   MySQLConnection._processInitialHandshake.initiateSSL.<anonymous closure> (package:mysql_client/src/mysql_client/connection.dart:323:13)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ ⛔ Skipping invalid packet: [2, 0, 0, 3, 1, 3]
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:163:12)
flutter: │ #1   MySQLConnection._processInitialHandshake.initiateSSL.<anonymous closure> (package:mysql_client/src/mysql_client/connection.dart:323:13)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Processing socket data. Current state is _MySQLConnectionState.initialHandshakeResponseSend
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:224:16)
flutter: │ #1   MySQLConnection._processInitialHandshake.initiateSSL.<anonymous closure> (package:mysql_client/src/mysql_client/connection.dart:323:13)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 💡 Got OK packet. Connection established
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:163:12)
flutter: │ #1   MySQLConnection._processInitialHandshake.initiateSSL.<anonymous closure> (package:mysql_client/src/mysql_client/connection.dart:323:13)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Processing socket data. Current state is _MySQLConnectionState.waitingCommandResponse
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   MySQLConnection._processCommandResponse (package:mysql_client/src/mysql_client/connection.dart:391:12)
flutter: │ #1   MySQLConnection._processSocketData (package:mysql_client/src/mysql_client/connection.dart:233:7)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Processing command response packet
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: sql.connect

I'm able to reproduce the exception while building from the main branch and directly from pub.dev. The connection doesn't connect in either cases, but for some reason the logging branch is able to establish the connection despite logging the invalid packet.

I suppose this issue is because of the latest changes that were recently made to the repository (related to invalid host issues/error handling issue - https://github.com/zim32/mysql.dart/issues/25).

Maybe handling the exception a bit differently could help, and also temporarily rolling back to a version where the above changes weren't made, could help the library from not breaking there for developers who are using MySQL and have designed their pubspec.yaml to rely on the latest version of the library (until this issue isn't resolved completely).

zim32 commented 2 years ago

As a temporary workaround you can

CREATE USER 'some_user'@'%' IDENTIFIED WITH mysql_native_password BY '12345';

Then grant access for this user to your database and use it

wustrong commented 2 years ago

Hello. Can you write your setup. Where is dart code. Where is mysql server? What version of mysql server?

here is the code:

    var settings = <String, dynamic>{
        'user': 'test',
        'password': 'test_123',
        'db': 'test_db',
      };
      var conn = MySQLConnectionPool(
        host: settings['host'] ?? '127.0.0.1',
        port: settings['port'] ?? 3306,
        userName: settings['user'] ?? '',
        password: settings['password'] ?? '',
        maxConnections: settings['maxConnections'] ?? 10,
        databaseName: settings['db'] ?? '',
        // optional,
        secure: settings['secure'] ?? false,
        collation: settings['collation'] ?? 'utf8mb4_general_ci',
      );

      var res = await conn.execute('select a.id, a.* from t_employee a');

Mysql Server version: 8.0.28 Homebrew(local)

zim32 commented 2 years ago

I am working on it. This is authentication protocol issue

wustrong commented 2 years ago

I am working on it. This is authentication protocol issue

mysql1 connect mysql server (above 8) without 'mysql_native_password' correctly.

has a plan to compatible with mysql 8 default password protocol?

zim32 commented 2 years ago

I am working on it. This is authentication protocol issue

mysql1 connect mysql server (above 8) without 'mysql_native_password' correctly.

has a plan to compatible with mysql 8 default password protocol?

Yes this library will be compatible with default mysql 8 auth protocol

zim32 commented 2 years ago

Ok. It should be fixed in latest release 0.0.23

MHShetty commented 2 years ago

Ok. It should be fixed in latest release 0.0.23

Yes this issue is now fixed in the latest release 👍 (Tried testing the latest pub.dev release)

Thanks a lot for looking into and fixing this issue @zim32!