Calling `ToCancellationToken` on completed task throws `ObjectDisposedException`
Open
Beginner friendly
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 11.2k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
When calling ToCancellationToken on a completed task, an exception occurred
UniTask.CompletedTask.ToCancellationToken();
// System.ObjectDisposedException: The CancellationTokenSource has been disposed.
The source code of ToCancellationToken is
var cts = new CancellationTokenSource();
Core(task, cts).Forget();
return cts.Token;
If the task is completed, cts will be disposed synchronously in Core() and then accessing cts.Token causes ObjectDisposeException
Is this a bug or by design?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ToCancellationToken implementation shown in the issue and reproduce it with UniTask.CompletedTask. Trace the synchronous completion and disposal path, then verify that calling ToCancellationToken on a completed task returns a usable token without throwing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100