Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomBuild MSBuild task has trouble cancelling. #9404

Closed
YuliiaKovalova opened this issue Nov 7, 2023 · 2 comments
Closed

CustomBuild MSBuild task has trouble cancelling. #9404

YuliiaKovalova opened this issue Nov 7, 2023 · 2 comments
Assignees
Labels
Partner request Priority:2 Work that is important, but not critical for the release triaged

Comments

@YuliiaKovalova
Copy link
Member

Repro Steps:

  1. Clone https://github.com/TileDB-Inc/TileDB and open a PowerShell into it.
  2. Run mkdir build && cd build.
  3. Run ../bootstrap.ps1.
  4. Run cmake --build . --config Release and wait a couple of seconds before the next step.
  5. Try to cancel the build with Ctrl-C.

Expected Result:
The build stops.

Actual Result:
Attempting to cancel the build...
C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): war
ning MSB4220: Waiting for the currently executing task "CustomBuild" to cancel. [C:\Users\v-evelynyou\TileDB\build\ep_c
atch.vcxproj]
Image

Customer Info:
Link to AzDO feedback work item.
Link to Developer Community feedback item.
[severity:It bothers me. A fix would be nice]

copied from #8999

Issue Description
We have a C++ codebase that uses CMake in a “superbuild” architecture, where an outer CMake project downloads our third-party dependencies, and the inner project contains our own code and is built afterwards.

The problem is that when I build the outer project, I cannot make it immediately stop via Ctrl-C and I have to kill it from the Task Manager. This hinders my development workflow.

Steps to Reproduce
Clone https://github.com/TileDB-Inc/TileDB and open a PowerShell into it.
mkdir build && cd build
Run ../bootstrap.ps1 (should not take long)
Run cmake --build . --config Release and wait a couple of seconds before the next step.
Try to cancel the build with Ctrl-C.
Expected Behavior
The build stops.

Actual Behavior
The build does not stop. Immediately after pressing Ctrl-C I get an Attempting to cancel the build... message.
image

After some time I getting a C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(248,5): warning MSB4220: Waiting for the currently executing task "CustomBuild" to cancel. [C:\Users\teo\code\TileDB\build\ep_magic.vcxproj]. The build will stop after the currently-building component of the outer project finishes (in this case it was a dependency, but in most cases when the main project gets built, the build is effectively uncancellable).

Analysis
I don’t think this is a problem of CMake because I can cancel the outer build on Unix with Makefiles. It seems that MSBuild struggles to kill the inner build.

Directly building the inner project can be cancelled without any problem.

Versions & Configurations
MSBuild version 17.6.3.22601
CMake version 3.26.0-msvc3

To find diagnostic information, see the original linked feedback ticket.

@YuliiaKovalova YuliiaKovalova added Priority:2 Work that is important, but not critical for the release Iteration:2023December labels Nov 7, 2023
@YuliiaKovalova
Copy link
Member Author

YuliiaKovalova commented Nov 7, 2023

Comment from C++ team:

"CustomBuild task is derived from ToolTask (owned by msbuild) which creates the tool process. To be able to cancel a console process, you need to send it console CTRL+BREAK event and for that you need to know its handle, which is private currently.

When cpp tasks are using tracker, tracker issues that event on cancellation:

https://devdiv.visualstudio.com/DevDiv/_git/VS?path=/src/xmake/DependencyTracking/Tracker/Tracker.cpp&version=GBmain&line=568&lineEnd=568&lineStartColumn=12&lineEndColumn=98&lineStyle=plain&_a=contents

But when process is launched without tracking (which is the case in CustomBuild), currently nobody sends the CTRL+BREAK event.

So ask to msbuild: either expose tool process handle to derived classes somehow (say, as some protected method) or issue CTRL+BREAK event to the tool process in ToolTask.Cancel().

Note that issuing CTRL+BREAK event and waiting for tool process exit is required to avoid corrupted outputs and problems with subsequent incremental build."

@JanKrivanek JanKrivanek added the needs-triage Have yet to determine what bucket this goes in. label Nov 10, 2023
@AR-May AR-May added Partner request and removed needs-triage Have yet to determine what bucket this goes in. labels Nov 14, 2023
@maridematte maridematte self-assigned this Nov 30, 2023
maridematte added a commit that referenced this issue Jan 19, 2024
Fix for #9404

Context
We currently do not send the cancelation event to tasks being run by ToolTask, as such, many children task take a long time to cancel, and sometimes they finish executing before said cancelation.
This change makes it possible for inherited classes to access the process and check the cancelation event during execution.

Changes Made
Separated the start of the process to another function that is overridable, as well as exposing the process information.

Notes
Issue will only be closed once C++ team has incorporated this change into the CustomBuild task.
@maridematte
Copy link
Contributor

The full resolution for this ticket depends on the C++ team to implement a solution on their side. If you're looking for further updates please check the original issue at the community feedback page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Partner request Priority:2 Work that is important, but not critical for the release triaged
Projects
None yet
Development

No branches or pull requests

4 participants