Random problems with connection to MySQL from Azure WebJob

1

I have application, which connects to MySQL database. Everything is fine when app runs on Windows Server 2016, but lastly I migrated it to Azure App Service as continous Web Job and I get completely randomly errors:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> 
MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired.  
The timeout period elapsed prior to completion of the operation or the server is not responding.
   at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Dapper.SqlMapper.<ExecuteImplAsync>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()``

I try to create connection every time when my app retrieves message from queue. I use Dapper and piece of my code, which connects to MySQL looks like this:

using (IDbConnection connection = new MySqlConnection(connectionString))
{
    return await connection.QueryAsync<Resource>(this._getContactsToSync);
}

MySQL version is 5.5 - quite old, but it's customer external source and I can't do anything with that. I tested three versions of MySQL drivers for .NET (8.0, 6.9, 6.10) - error occurs with every of them.

I found somewhere information, that this situation could be caused by to many open sockets, but I tested app locally with netstat command and everything looks good.

My issue is similar to this: Random connection problems from Azure C# app to remote MySQL server, but there is'nt any helpful answer.

I've never done anything with MySQL, so I'm not an expert with this tool. Maybe someone has similar situation???

c#
mysql
.net
azure
azure-webjobs
asked on Stack Overflow Jan 17, 2020 by robr

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0