Task ate my data! Unexpected results at runtime. No errors in core stack.
See original GitHub issueDescription of the issue
Converting an existing async function to the new F# 6 task CE throws up some unexpected and undesirable behaviour:
- Runtime failure, not compiler failure
- No errors thrown in core stack at all, just lost data
Steps required to reproduce the problem:
The attached ZIP file contains two .NET Interactive Notebooks, test_async.dib, which is the original function using async, and test_task.dib, which uses the new task CE. Running them yields the results described. The data array gets swallowed up.
Other notes:
- Weird error if you remove unused fromAccount variable declaration: System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed
Expected result
True, [ ( 2022-06-28 18:06:32Z, 3, 4, 5, { Some(6): Value: 6 }, { Some(1): Value: 1 }, True, ( { Some(7): Value: 7 }, True, 2022-06-28 18:06:32Z ) ), ( 2022-06-28 18:06:32Z, 3, 4, 5, { Some(6): Value: 6 }, { Some(1): Value: 1 }, True, ( { Some(7): Value: 7 }, True, 2022-06-28 18:06:32Z ) ), ( 2022-06-28 18:06:32Z, 3, 4, 5, { Some(6): Value: 6 }, { Some(1): Value: 1 }, True, ( { Some(7): Value: 7 }, True, 2022-06-28 18:06:32Z ) ) ], 3
Actual result
True, null, 3
Known workarounds
- Change task to async -> Works, but reverts to slower workflow. The code has no real async operations.
- Move mapPrioritiesTransfers tasks inside match conditions -> Works, but high overhead to convert code
- remove minOrder and set isPrio to true -> Works, but altered behaviour
There is no clear understanding of when we need a workaround for what, leading to a lack of ability to trust the new task-construct, so it seems rather fragile.
Related information
- Win 11
- .NET SDK 6
- F# 6.0
- VS2022 and VSCode
Issue Analytics
- State:
- Created a year ago
- Comments:14 (13 by maintainers)
Top GitHub Comments
OK I have this fixed - at least the data corruption part (caused by incorrect codegen).
The bug will occur when a nested task fails state machine compilation. A realiable workaround is if a nested task gives
FS3511
you should move it out to a separate function.The failure of state machine compilation is separate issue.
@simontreanor
Array.map
in tasks https://github.com/dotnet/fsharp/issues/12359, it has been fixed but it’s possible the fix is not yet in .NET Notebooks.@Thorium What’s your exact VS or VSCode or .NET SDK version please
BTW I’d imagine a fix is to move the chunks of synchronous code out of
task { ... }