Skip to content

IProcess WaitForExit(int) does not just observe whether the process has exited, it will kill a running process #4321

@richardissimo

Description

@richardissimo

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

Cake runner

Cake .NET Tool

Cake version

4.0.0

Operating system

Windows

Operating system architecture

64-Bit

CI Server

No response

What are you seeing?

I have a cake build which launches multiple processes, using StartAndReturnProcess:

            var process = StartAndReturnProcess(runServiceBatPath.FullPath, settings);

I keep hold of those processes in a collection, and I have a loop which keeps an eye on those processes to see whether they are still running or not.

I am using "WaitForExit(1)" to see whether the process is still running or not, because there isn't a property on IProcess like the one on System.Diagnostics.Process called HasExited; so WaitForExit(int) should do the same thing.

But those processes seem to be mysteriously dying, which I've tracked down to being in the Cake code, if the process is still running, it kills the process. This is not only terrible (because there is no way of checking whether the process is still running); but fixing it will be a breaking change.

What is expected?

I would expect WaitForExit(1) to wait for up to a millisecond, before returning whether the process has exited or not (just like the documentation says). I do not expect it to kill the process.

Steps to Reproduce

The simplest way of replicating is to start any process that you know will remain running for a while - ideally one that you can see visually, or is easy to identify in Task Manager.

 var process = StartAndReturnProcess(yourProcessPathGoesHere);
 if (process.WaitForExit(1))
 {
     throw new Exception("Process is not running");
 }

When you run this, you will find that the WaitForExit has actually killed the process, rather than just observing whether it has exited or not.

Output log

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions