Skip to content

[Bug]: Please re-initilize "_terminatedTool" in class Microsoft.Build.Utilities.ToolTask #8541

Closed
@gpwen

Description

@gpwen

Issue Description

In the following code:
https://github.com/dotnet/msbuild/blob/main/src/Utilities/ToolTask.cs

The private field _terminatedTool has not be initialized in method ExecuteTool(). As a result, in rare cases where:

  1. ToolTask.Execute() being called multiple times from derived classes, and;
  2. The tool execution being timed out once.

Such timed-out state will be incorrectly permanent, impacting all following ToolTask.Execute() calls, and forcing the method to return false even if the execution succeeded.

The problem can be easily addressed by reinitializing _terminatedTool field to false in method ExecuteTool(), along with other private fields.

Thanks!

Steps to Reproduce

  1. Create a CLI tool that would wait the amount of time (ms) specified on command line;
  2. Create a ToolTask derived class to execute that tool;
  3. Override Execute(), calling base.Execute() multiple times to execute the tool multiple times;
  4. In the first execution, set delay to a larger value (>100s), and set it to smaller value in all subsequent execution (< 1s);
  5. Set Timeout of the task to 5s, so the first call will timed out, and subsequent ones won't;
  6. Watch how all subsequent base.Execute() returns false, so the task never succeeds.

Expected Behavior

The first execution timed out (and fail), but subsequent execution should succeed.

Actual Behavior

After the first execution timed out, all subsequent execution failed even if they actually succeeded.

Analysis

Private field _terminatedTool has not been reinitialized correctly in ToolTask.ExecuteTool() method.

Versions & Configurations

The latest version (17.5).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions