Repository navigation
Read the DisposeAsync result in async builders when it completes successfully - #386
Merged
Merged
Conversation
The asyncResult, asyncOption, asyncResultOption, parallelAsyncResult and parallelAsyncValidation builders returned without GetResult when the DisposeAsync ValueTask had already completed successfully. An IValueTaskSource then never saw its result read. Also compile the asyncOption IAsyncDisposable tests on every non-Fable target. They were under #if NET7_0, which the test project no longer targets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the async-disposal fix.
No open issues 🎉
What changed in this PR
This PR fixes successful async disposal in five FsToolkit.ErrorHandling computation-expression builders, extending the task-builder fix from #385 to the async builders.
Changes:
- Calls
GetResult()when a disposalValueTaskhas already completed successfully, ensuring its result is consumed. - Adds completed and pending disposal regression cases for all five builders and enables existing
asyncOptiondisposal tests on supported .NET targets. - Documents the fix and the need to recompile assemblies that inline these builders.
| File | Description |
|---|---|
tests/FsToolkit.ErrorHandling.Tests/TestHelpers.fs |
Adds shared completed and pending disposal checks. |
tests/FsToolkit.ErrorHandling.Tests/ParallelAsyncValidationCE.fs |
Adds disposal result-consumption tests. |
tests/FsToolkit.ErrorHandling.Tests/ParallelAsyncResultCE.fs |
Adds disposal result-consumption tests. |
tests/FsToolkit.ErrorHandling.Tests/AsyncResultOptionCE.fs |
Adds disposal result-consumption tests. |
tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs |
Adds disposal result-consumption tests. |
tests/FsToolkit.ErrorHandling.Tests/AsyncOptionCE.fs |
Adds regression tests and corrects the disposal-test compilation guard. |
src/FsToolkit.ErrorHandling/ParallelAsyncValidationCE.fs |
Consumes already-successful disposal results. |
src/FsToolkit.ErrorHandling/ParallelAsyncResultCE.fs |
Consumes already-successful disposal results. |
src/FsToolkit.ErrorHandling/AsyncResultOptionCE.fs |
Consumes already-successful disposal results. |
src/FsToolkit.ErrorHandling/AsyncResultCE.fs |
Consumes already-successful disposal results. |
src/FsToolkit.ErrorHandling/AsyncOptionCE.fs |
Consumes already-successful disposal results. |
RELEASE_NOTES.md |
Records the fix and recompilation guidance. |
Review effort: Balanced
…etresult # Conflicts: # RELEASE_NOTES.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
useon anIAsyncDisposableinasyncResult,asyncOption,asyncResultOption,parallelAsyncResult, andparallelAsyncValidationcallsDisposeAsync()and gets aValueTask. When thatValueTaskhad already completed successfully,TryFinallyAsyncreturned without a call toGetResult:The
ValueTaskcontract requires each instance to be consumed once. AnIValueTaskSourcecan do work inGetResult. For example, aPoolingAsyncValueTaskMethodBuilderbox returns to its pool inGetResult. With the old code, that source never saw its result read. Faulted and canceled disposals were not affected, because they take theAsTaskbranch.This PR changes the success branch to
return vTask.GetAwaiter().GetResult()in the five builders. #385 fixed the same problem in thetask*builders.Tests
TestHelpers.asyncBuilderDisposalSucceedsTestsruns the existingassertAsyncDisposalOutcome(withObservedDisposalSource, which countsGetResultcalls) for a completed and a pending successful disposal. Each of the five builders has both cases.completed successful disposalcases fail onmasterwithThe DisposeAsync result must be read exactly once. The 5pending successful disposalcases pass onmaster. They guard theAsTaskbranch.tests/FsToolkit.ErrorHandling.Tests/AsyncOptionCE.fs: theIAsyncDisposabletests were under#if NET7_0. The test project targetsnet10.0;net11.0, so they did not compile. They now use#if !FABLE_COMPILER, the same as the sibling files.Not changed
DisposeAsyncfault,Async.TryFinallyAsyncraises anAggregateException. This PR does not change that.#if !FABLE_COMPILER && NETSTANDARD2_1in five test files also never compiles for the test targets. That is a separate cleanup.srcchanges and the tests stay inside#if !FABLE_COMPILER. Fable 5.27.0 (the latest release) rejectsValueTask.IsCompletedSuccessfully,GetAwaiter,GetResult, andAsTaskfor JavaScript and Python withis not supported by Fable.Types of changes
The five members are
inline. An assembly that inlined them keeps the old body until it is recompiled.Checklist
RELEASE_NOTES.md🤖 Generated with Claude Code