MySqlConnector: MySql.Data.MySqlClient.MySqlException: Couldn't connect to server ---> System.IO.EndOfStreamException: Expected to read 4 header bytes but only received 0

We recently updated Mysqlconnector from 0.7.3 to .45.1 on a dotnet core 2.0 application.

We also turned connection pool on, to avoid information_schema.parameters calls for stored procedures.

We are seeing this exception consistently. We had to roll back. I’ve looked at Global variables and they seem to be identical to lower stack environments where we are unable to reproduce the issue.

 at MySqlConnector.Utilities.ValueTaskExtensions.<ContinueWith>d__0`2.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Utilities\ValueTaskExtensions.cs:line 8
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySqlConnector.Utilities.ValueTaskExtensions.<ContinueWith>d__0`2.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Utilities\ValueTaskExtensions.cs:line 8
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 1230
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySqlConnector.Core.ServerSession.<ConnectAsync>d__58.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 356
   --- End of inner exception stack trace ---
   at MySqlConnector.Core.ServerSession.<ConnectAsync>d__58.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 380
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ConnectionPool.<CreateMinimumPooledSessions>d__18.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs:line 346
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__10.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs:line 40
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__81.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 405
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__22.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 183
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

our code looks like this:

    public async Task<Dictionary<Type, IEnumerable<object>>> QueryMultipleAsync(string sp, object args, CommandType type, IEnumerable<Type> returnTypes)
    {
        var results = new Dictionary<Type, IEnumerable<object>>();
        using (var conn = new MySqlConnection(_connectionString))
        {
            await conn.OpenAsync();
            try
            {
                    var grid = await conn.QueryMultipleAsync(sql: sp, param: args, commandType: type);
                    foreach (Type returnType in returnTypes)
                    {
                        var returnValues = grid.Read(returnType);
                        if (returnValues.Any())
                        {
                            results.Add(returnType, returnValues);
                        }
                    }
            }
            catch { throw; }
            finally
            {

                if (conn != null && conn.State != ConnectionState.Closed)
                    conn.Close();
            }
        }

        return results;
    }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 30 (8 by maintainers)

Most upvoted comments

This was a configuration issue on our side and is now resolved. Thank you for all your help.

@iamomie Any chance you can elaborate on what the issue was? We’re facing the same issue right now with this configuration string:

Server={dbServer};Port={dbPort};Database={dbName};Uid={dbUser};pwd={dbPassword};SslMode=none;default command timeout=10;Connection Timeout=3;MinimumPoolSize=20;maximumpoolsize=500

@iamomie how to “added a test to make sure the connection was good and if not retry”,

Our configuration string like it: server=127.0.0.1;port=3309;database=lemon_novel;uid=root;pwd=xxxx;Allow User Variables=True;Connection Timeout=30;SslMode=None;Charset=utf8mb4;