question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Task ate my data! Unexpected results at runtime. No errors in core stack.

See original GitHub issue

Description 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.

test.dib.zip

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

  1. Change task to async -> Works, but reverts to slower workflow. The code has no real async operations.
  2. Move mapPrioritiesTransfers tasks inside match conditions -> Works, but high overhead to convert code
  3. 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:closed
  • Created a year ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
dsymecommented, Jun 29, 2022

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.

2reactions
dsymecommented, Jun 29, 2022

@simontreanor

  1. What exact version of .NET notebooks do you have please?
  2. This bug looks highly relevant, as it is related to uses of 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.
  3. Could you try replacing Array.map and perhaps any other inlined Array functions with your own non-inlined versions

@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 { ... }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected end of request content Kestrel ASP.NET Core
When I run this request as part of WCF contract in WebApi1 I got stacktrace: at System.Threading.Tasks.Task.
Read more >
Getting fatal errors when trying to do a data.table printout
After a few minutes, I get a pop-up that says "Fatal error: Unexpected exception: bad allocation". Once I click OK, I get another...
Read more >
The 10 Most Common Mistakes in C# Programming
Don't fall into one of these C# programming mistakes that even savvy developers can find problematic. Read on to see all 10.
Read more >
Is software getting worse?
I recently stumbled upon “Software disenchantment,” a post by Nikita Prokopov. It called to mind Maciej Cegłowski's post “The Website ...
Read more >
Disk quota exceeded problem
In a program I was running, I had output get written to a file. I ran into an infinite loop and had to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found