Bug #89165 read wmi very slow Reading from the stream has failed.

Submitted: 10 Jan 2018 1:25 Modified: 11 Jan 2018 11:28
Reporter: 富 姜 Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S5 (Performance)
Version:6.9.10 OS:Windows
Assigned to: CPU Architecture:Any

[10 Jan 2018 1:25] 富 姜
Description:
--error message
Reading from the stream has failed.

this error because of read wmi is too long.
read OSDetails  is very slow,sometime is over 30s .

How to repeat:
--check code
namespace ConsoleApplication1
{
    class Program
    {
        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");
                     }
                   }

    }
}
}

//repeat code

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
          while(true){
            try{
           MySqlConnection conn = new MySqlConnection("server=server;port=;database=dbtest;uid;");
           conn.Open();
           MySqlCommand cmd = conn.CreateCommand();
           cmd.CommandType = System.Data.CommandType.Text;
           cmd.CommandText = "select @@hostname";
           cmd.ExecuteNonQuery();
         }
         catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
         }
        }
    }
}

Suggested fix:
    [DisplayName("_os_details")]
    public string OSDetails
    {
        get
        {
            string os = string.Empty;
            try
            {
                //采用取环境变量中的版本就OK绕过了-jiangxf
                os = Environment.OSVersion.VersionString;
                //这个在win7以上版本不知道为啥会很慢超过30s导致服务器报错
                // Reading from the stream has failed.
                //  var searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
                //  var collection = searcher.Get();
                //  foreach (var mgtObj in collection)
                //  {
                //    os = mgtObj.GetPropertyValue("Caption").ToString();
                //    break;
                //  }
            }
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }

            return os;
        }
    }
[11 Jan 2018 11:28] Chiranjeevi Battula
Hello 富 姜,

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

Thanks,
Chiranjeevi.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.