Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in AsyncLazy handling of cancellation #18209

Closed
majocha opened this issue Jan 7, 2025 · 0 comments · Fixed by #18211
Closed

Bug in AsyncLazy handling of cancellation #18209

majocha opened this issue Jan 7, 2025 · 0 comments · Fixed by #18211

Comments

@majocha
Copy link
Contributor

majocha commented Jan 7, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant