Bug #88687 authenticate fail when open connection
Submitted: 29 Nov 2017 2:01 Modified: 4 Dec 2017 3:40
Reporter: yx jiang Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.9.9 OS:Any
Assigned to: CPU Architecture:Any
Tags: auth failed, WMI query

[29 Nov 2017 2:01] yx jiang
Description:
When openning connection using Connector/NET, we occasionally recieve error message "Authentication to host 'xxxx' for user 'yyyy' using method 'mysql_native_password' failed with message: Reading from the stream has failed."

How to repeat:
This error occured occasionally.So when error happend on windows system, the code below will print overhead WMI query.

On system runnin normally chance to reproduct the erorr is less.

static void Main(string[] args)
{
    Stopwatch watch = new Stopwatch();
    while (true)
    {
        watch.Restart();
        var searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
        var collection = searcher.Get();
        foreach (var mgtObj in collection)
        {
            string os = mgtObj.GetPropertyValue("Caption").ToString();
        }
        watch.Stop();
        Console.WriteLine(watch.ElapsedMilliseconds);
        if (watch.ElapsedMilliseconds >= 1000)
        {
            Console.WriteLine("-------------");
            File.AppendAllText("abc.txt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") +","+ watch.ElapsedMilliseconds + "\r\n");
        }
    }
}

Suggested fix:
Try another way to get OSDetails to avoid overhead WMI query

public string OSDetails
{
  get
  {
    os = Environment.OSVersion.VersionString;
   /*try
{
      var searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
      var collection = searcher.Get();
      foreach (var mgtObj in collection)
      {
        os = mgtObj.GetPropertyValue("Caption").ToString();
        dbglog.dolog(String.Format("MysqlDefs::OSDetails::foreach{0}", os.ToString()));
        break;
      }
    }
   catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }*/
return os;
  }
}
[29 Nov 2017 6:20] Bradley Grainger
Regarding the error message "Authentication to host 'xxxx' for user 'yyyy' using method 'mysql_native_password' failed with message: Reading from the stream has failed", see the last comment on bug #76597.

Regarding the overhead of WMI when making a connection, see bug #80030.
[29 Nov 2017 10:13] Chiranjeevi Battula
Hello yx jiang,

Thank you for the bug report.
This is most likely duplicate of Bug #76597, please see Bug #76597

Thanks,
Chiranjeevi.
[4 Dec 2017 3:40] yx jiang
This is the same problem of bug 80030. 

But in newest connector/net, it is not fixed
[31 Dec 2017 6:33] Sanjay Kothari
Hi Team,

I am also facing the same issue while opening the connection with MYSQL. It was taking too long time (15 seconds).
.Net Connector : 6.9.9 / 6.9.10
MySQl DB : 5.6.36 (MySQL Community Server).

The bug #88687 reported with issue of "Authentication to host 'xxxx' for user 'yyyy' using method 'mysql_native_password' failed with message: Reading from the stream has failed" is not resolved yet.

If bug #88687 is somehow connected with slow connectivity of .net connector as mentioned in bug #80030 then it must be resolved earlier because patch is already provided 2 years before but not fixed in new .net connector update.

Please help us to resolve this issue.

Regards,
Sanjay
[31 Dec 2017 6:45] Sanjay Kothari
Also, when I am debugging the code from Visual studio 2015 then I am not facing any issues while connecting to database. I am getting this issue only when I am publishing my code and hosting it in IIS server.

Regards,
Sanjay
[1 Mar 2018 8:39] Muhammed Khalifa
Thanks yx jiang, this has fixed our issue in production after weeks of diagnosis.

I've changed the code to:

    private static readonly string _osVersion = Environment.OSVersion.VersionString;

    [DisplayName("_os_details")]
    public string OSDetails => _osVersion;

I don't expect this to change at runtime.
[6 Mar 2018 8:04] Muhammed Khalifa
Just to add to the previous comment, there's difference in the info:

Environment.OSVersion.VersionString gives you, for e.g:

OSVersion: Microsoft Windows NT 5.1.2600.0

ManagementObjectSearcher gives you the product name, for e.g:

Microsoft Windows 7 Professional

We could cache the result of the original ManagementObjectSearcher query, as i don't expect the OS to change while it's running.