SapientGuardian / mysql-connector-net-netstandard

ADO.NET driver for MySQL targeted against netstandard 1.3
GNU General Public License v2.0
46 stars 15 forks source link

UseCompression=true in Connection String causes Open() to hang. #17

Closed galador closed 8 years ago

galador commented 8 years ago

I seem to be having some issues when trying to use compression in the connection string. It just hangs on Open() forever.

Here's what I did to reproduce:

Create a test table:

CREATE DATABASE testdb;
CREATE USER 'testuser'@'%' IDENTIFIED BY 'testpassword';
GRANT ALL PRIVILEGES ON testdb.* to 'testuser'@'%';
FLUSH PRIVILEGES;
USE testdb;
CREATE TABLE testtable (id INT, name VARCHAR(100));
INSERT INTO testtable VALUES (1,'Testing!');

Create a console app with the following code:

using System;
using MySql.Data.MySqlClient;

namespace TestMySql
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var connStr = "Host=mysql;Database=testdb;User=testuser;Password=testpassword"; //Basic connection string
            using (var conn = new MySqlConnection(connStr))
            {
                Console.WriteLine("About to open uncompressed connection");
                conn.Open();

                Console.WriteLine(conn.ServerVersion);
                Console.WriteLine(conn.UseCompression);

                WriteData(conn);
                Console.WriteLine("");
            }

            connStr += ";compress=True";
            using (var conn = new MySqlConnection(connStr))
            {
                Console.WriteLine("About to open compressed connection");
                conn.Open(); //Hangs here
                WriteData(conn);
                Console.WriteLine("With compression, it never gets here...");
                Console.WriteLine("");
            }
        }

        private static void WriteData(MySqlConnection conn)
        {
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = "SELECT * FROM testtable";
                using (var r = cmd.ExecuteReader())
                {
                    while (r.Read())
                    {
                        var id = r["id"].ToString();
                        var name = r["name"].ToString();

                        Console.WriteLine($"ID = {id}, Name = {name} ");
                    }
                }
            }
        }
    }
}

And here's the project.json:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    },
    "SapientGuardian.MySql.Data": "6.9.8-rc2-007"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  },

  "tooling": {
    "defaultNamespace": "TestMySql"
  }
}

Get the following results:

TestMySql> dotnet run
Project TestMySql (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
About to open uncompressed connection
5.6.28-0ubuntu0.15.10.1
False
ID = 1, Name = Testing!
About to open compressed connection
^C

TestMySql> dotnet --version
1.0.0-preview1-002702

I have another project using "full" .NET, and the official MySQL client, and it connects to the server with compression fine.

Please let me know if I can provide further information.

SapientGuardian commented 8 years ago

I was able to reproduce the problem, and have a fix for it in #18. Will merge when the ci builds complete succesfully.

SapientGuardian commented 8 years ago

The fix is being published in version 6.9.8-rc2-008. Please re-open the issue if it doesn't resolve the problem you're having. Thanks for the bug report!