Blue screen when using Ping
Asked Answered
I

2

5

I'm running into the bug where it BSODon ending debugging in the middle of a ping.

I have a few ways to disable it in my (wpf) application (where I ping continuously), but sometimes I forget to do so and BSOD.

I'd like to get around that say by changing a global AllowRealPinging variable and sleeping for 2 seconds in a callback before exiting the debugger so I don't BSOD.

Ileus answered 19/7, 2013 at 23:6 Comment(0)
K
13

This is a known bug in Windows 7, you'll get a BSOD with bug-check code 0x76, PROCESS_HAS_LOCKED_PAGES in tcpip.sys when you terminate the process. The most relevant feedback article is here. Also covered in this SO question. No great answers there, the only known workaround is to fallback to a .NET version earlier than 4.0, it uses another winapi function that doesn't trigger the driver bug.

Avoiding pinging while you debug is certainly the best way to avoid this problem. Your desired approach is not going to work, your program is entirely frozen when it hits a breakpoint, kaboom when you stop debugging.

The simplest way is to just not starting pinging in the first place in the specific case of having a debugger attached. Use the System.Diagnostic.Debugger.IsAttached property to detect this in your code.

Kippy answered 26/7, 2013 at 18:19 Comment(4)
Just got exactly this problem in Windows 10, seems like the bug is still there. The Connect issue has disappeared though.Legitimize
I am hitting this under Windows 2012R2. Apparently this has been around since 2011! Is there a cached copy of the connect bug or any details that confirm this is a Windows bug rather than a driver issue? social.technet.microsoft.com/Forums/windows/en-US/…Glory
I'm running Windows Server 2016 RTM with Intel network drivers and I can reliably reproduce this issue. Someone could very easily author a userland-only DoS payload with this technique - and I've found reports of this issue going back to 2011 and earlier. It is surprising (and very disappointing) that this is still an issue - though I concede it could be an issue with Intel's drivers and so absolves MS of primary responsibility.Lacagnia
Same bug in windows 8.1 with latest updates and installed and latest Intel NIC driver.Wept
S
2

This is a good way around:

private void GetPing(){

            Dictionary<string, string> tempDictionary = this.tempDictionary;  //Some adresses you want to test
            StringBuilder proxy = new StringBuilder();

            string roundTripTest = "";
            string location;
            int count = 0;  //Count is mainly there in case you don't get anything

            Process process = new Process{

                StartInfo = new ProcessStartInfo{
                    FileName = "ping.exe",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true,

                }

            };

            for (int i = 0; i < tempDictionary.Count; i++){

                proxy.Append(tempDictionary.Keys.ElementAt(i));

                process.StartInfo.Arguments = proxy.ToString();

                do{
                    try{

                        roundTripTest = RoundTripCheck(process);

                    }
                    catch (Exception ex){

                        count++;

                    }

                    if (roundTripTest == null){

                        count++;

                    }

                    if (count == 10 || roundTripTest.Trim().Equals("")){

                        roundTripTest = "Server Unavailable";

                    }

                } while (roundTripTest == null || roundTripTest.Equals(" ") || roundTripTest.Equals(""));
            }

            process.Dispose();

        }

RoundTripCheck method, where the magic happens:

       private string RoundTripCheck(Process p){


            StringBuilder result = new StringBuilder();
            string returned = "";

            p.Start();

            while (!p.StandardOutput.EndOfStream){

                result.Append(p.StandardOutput.ReadLine());

                if (result.ToString().Contains("Average")){

                    returned = result.ToString().Substring(result.ToString().IndexOf("Average ="))
                                     .Replace("Average =", "").Trim().Replace("ms", "").ToString();
                    break;
                }


                result.Clear();

            }

            return returned;

        }

I had the same problem, this solves it!

Sheepskin answered 31/7, 2017 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.