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

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

Closed
galador opened this issue Jun 25, 2016 · 2 comments
Closed

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

galador opened this issue Jun 25, 2016 · 2 comments

Comments

@galador
Copy link

galador commented Jun 25, 2016

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
Copy link
Owner

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

SapientGuardian added a commit that referenced this issue Jun 25, 2016
Fixes #17. Changed MySqlStream to use BufferedStream.
@SapientGuardian
Copy link
Owner

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!

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

No branches or pull requests

2 participants