AutomatedTester.BrowserMob icon indicating copy to clipboard operation
AutomatedTester.BrowserMob copied to clipboard

.Stop() is not stopping

Open axtens opened this issue 9 years ago • 1 comments

I've been having an issue driving both browsermob-proxy-2.1.0-beta-3 and browsermob-proxy-2.1.0-beta-4 with AutomatedTester namely that .Stop() is not terminating the java side of things nor is it terminating the CMD side of things either.

As a temporary measure, given my naivete, I've modified Stop as follows

    public void Stop()
    {            
        if (_serverProcess != null && !_serverProcess.HasExited)
        {
            _serverProcess.Kill();
            //_serverProcess.CloseMainWindow();
            //_serverProcess.Dispose();
            _serverProcess = null;
        }            
    }

I'm yet to see if this improves things or not. I fancy it leaves a lot of garbage lying around. Is there a better way of making sure that Stop really does Stop? Should I implement Abort and put the Kill in there?

I've also made _serverProcess public so that I can see what the process itself is up to.

axtens avatar Feb 04 '16 07:02 axtens

Right, I've reinstated the Stop() code. I've left the _serverProcess as public and am now using

/// <summary>
/// Kill a process, and all of its children, grandchildren, etc.
/// </summary>
/// <param name="pid">Process ID.</param>
private static void KillProcessAndChildren(int pid)
{
    ManagementObjectSearcher searcher = new ManagementObjectSearcher
      ("Select * From Win32_Process Where ParentProcessID=" + pid);
    ManagementObjectCollection moc = searcher.Get();
    foreach (ManagementObject mo in moc)
    {
        KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
    }
    try
    {
        Process proc = Process.GetProcessById(pid);
        proc.Kill();
    }
    catch (ArgumentException)
    {
        // Process already exited.
    }
}

and handing it the _serverProcess.Id in the hope that it clobbers both the CMD and the child java.

axtens avatar Feb 04 '16 08:02 axtens