From 28917c44d645b5696f37a306cf936643ec8cd265 Mon Sep 17 00:00:00 2001 From: iforapsy Date: Tue, 20 Dec 2016 06:20:08 -0800 Subject: [PATCH] Do not propagate exceptions from Process.Kill() if the process actually exits (#166) * Ignore more exceptions from Process.Kill() Sometimes we get an InvalidOperationException when we kill a process that is already dead and other times we get a Win32Exception. Let's ignore all exceptions from killing a process if it has exited. * Fix key name typo in README.md The name of the key has an underscore, not a hyphen. --- README.md | 2 +- src/Core/WinSWCore/Util/ProcessHelper.cs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 098ebda..c1b0cd7 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,6 @@ New versions with fixes may be released on-demand. ### Build Environment * IDE: [Visual Studio Community 2013](http://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx) (free for open-source projects) -* `winsw-key.snk` should be available in the project's root in order to build the executable +* `winsw_key.snk` should be available in the project's root in order to build the executable * You can generate the certificate in "Project Settings/Signing" * The certificate is in .gitignore list. Please do not add it to the repository diff --git a/src/Core/WinSWCore/Util/ProcessHelper.cs b/src/Core/WinSWCore/Util/ProcessHelper.cs index 0decf70..f913480 100644 --- a/src/Core/WinSWCore/Util/ProcessHelper.cs +++ b/src/Core/WinSWCore/Util/ProcessHelper.cs @@ -66,9 +66,15 @@ namespace winsw.Util Logger.Warn("SIGINT to " + pid + " failed - Killing as fallback"); proc.Kill(); } - catch (ArgumentException) + catch (Exception ex) { + if (!proc.HasExited) + { + throw; + } + // Process already exited. + Logger.Warn("Ignoring exception from killing process because it has exited", ex); } }