Skip to content

Bug in AsyncLazy handling of cancellation #18209

@majocha

Description

@majocha

Cancelling a request should not cause a TaskCanceledException to surface from AsyncMemoize but with recent changes it sometimes do:

System.AggregateException : One or more errors occurred.
---- System.Exception : Seed 815014682 failed on iteration 3: System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)    at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at <StartupCode$FSharp-Compiler-Service>.$AsyncMemoize.catchHandler@1[t](Exception exn) in D:\a_work\1\s\src\Compiler\Facilities\AsyncMemoize.fs:line 58
at <StartupCode$FSharp-Compiler-Service>[email protected](Exception x)
at Microsoft.FSharp.Control.AsyncPrimitives.CallFilterThenInvoke[T](AsyncActivation1 ctxt, FSharpFunc2 filterFunction, ExceptionDispatchInfo edi) in D:\a_work\1\s\src\FSharp.Core\async.fs:line 547
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 114 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at [email protected]() in D:\a_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 365
---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)    at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
<---


---- System.Exception : Seed 815014682 failed on iteration 2: System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)    at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at <StartupCode$FSharp-Compiler-Service>.$AsyncMemoize.catchHandler@1[t](Exception exn) in D:\a_work\1\s\src\Compiler\Facilities\AsyncMemoize.fs:line 58
at <StartupCode$FSharp-Compiler-Service>[email protected](Exception x)
at Microsoft.FSharp.Control.AsyncPrimitives.CallFilterThenInvoke[T](AsyncActivation1 ctxt, FSharpFunc2 filterFunction, ExceptionDispatchInfo edi) in D:\a_work\1\s\src\FSharp.Core\async.fs:line 547
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 114 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at [email protected]() in D:\a_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 365
---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.Ge



Stack trace
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout)
   at CompilerService.AsyncMemoize.Stress test() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 388
----- Inner Stack Trace #1 (System.Exception) -----
   at [email protected]() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 379
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at [email protected]() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 381
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at [email protected]() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 381
----- Inner Stack Trace #2 (System.Exception) -----
   at [email protected]() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 379
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at [email protected]() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 381
----- Inner Stack Trace #3 (System.Exception) -----
   at [email protected]() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 379
----- Inner Stack Trace #4 (System.Exception) -----
   at [email protected]() in D:\a\_work\1\s\tests\FSharp.Compiler.ComponentTests\CompilerService\AsyncMemoize.fs:line 379

TaskCanceledException

Repro steps

Locally it is sufficient to select all AsyncMemoize tests and execute "run until failure" in VS. After few hundred iterations or less the failure will occur.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions