Race condition in any code first checking a process is alive and then calling Process.Kill() - by Dmitry Me

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 776207 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 1/10/2013 2:42:17 AM
Access Restriction Public


I have a Process object that is associated to a running process and I want to wait till it exits and then if it failed to exit in reasonable time I want to kill the process. Here's my code:

if( !process.WaitForExit( someTime ) ) {

If the process exits between the lines such that WaitForExit() returns "false" but the process has exited before Kill() runs or in the middle of Kill() being run I get InvalidOperationException with this call stack:

Cannot process request because the process (ActualProcessIdHere) has exited.
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
at System.Diagnostics.Process.Kill()
//my code calling Process.Kill() here

Any code checking for the process being alive and then killing the process will have this race condition. Therefore it's impossible to guarantee there's no exception.

This exception seems useless and redundant. The purpose of Kill() is to end the process and the process has ended - okay, let it be, no exception required.
Sign in to post a comment.
Posted by Microsoft on 1/15/2013 at 12:12 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Posted by Dmitry Me on 1/14/2013 at 5:08 AM
I've added a concise code snippet. The timing constants are deliberately chosen to always produce the error.
Posted by Microsoft on 1/14/2013 at 12:30 AM
I am currently standing by for an update from you and would like to know how things are going on your end. If you could get back to me at your earliest convenience with information I request, we will be able to make headway towards a resolution. I look forward to hearing from you.
Posted by Microsoft on 1/10/2013 at 10:30 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 1/10/2013 at 3:35 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)