cake-build / cake-build/cake

Task getting cancelled when awaited by AsyncFrostingTask

Open
#3,462 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.2k
Forks
778
Avg merge
3h 37m
Merged PRs (30d)
21

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched [issues](https://github.com/cake-build/cake/issues) to ensure it has not already been reported

### Cake runner

Cake Frosting

### Cake version

1.1.0

### Operating system

Windows

### Operating system architecture

64-Bit

### CI Server

_No response_

### What are you seeing?

My setup is as follows
AsyncFrostingTask.RunAsync awaits
CustomCode.BuildAsync

CustomCode.BuildAsync is a method that returns a Task from a private CustomMethodAsync that also returns a Task, which comes from Process.WaitAsync.

So the async portion is Process.WaitAsync, which should be returned back to AsyncFrostingTask.RunAsync which awaits it.

However, when I do this, I immediately get a "TaskCanceledException" and the Task doesn't run properly.

I put a try/catch around the CustomCode.BuildAsync call, but it doesn't catch anything.

However, when I go into BuildAsync and CustomMethodAsync and make them async methods that await Process.WaitAsync themselves, everything works as expected and the exception doesn't happen.

### What is expected?

AsynFrostingTask should run Tasks without arbitrarily canceling them.

### Steps to Reproduce

I haven't tried a min repo, but the problem immediately happened when I switched from calling async Task code to calling code that returned a Task without awaiting it, and went away when I switched back.

### Output log

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at AsyncFrostingTask.RunAsync and trace how it awaits the Task returned by CustomCode.BuildAsync, then follow the call through CustomMethodAsync to Process.WaitAsync. First create a minimal reproduction of the reported TaskCanceledException, comparing direct Task returns with methods that await internally. Done means the task completes without arbitrary cancellation and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.