dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.56k stars 119 forks source link

AsyncLazy broken after rapid cancellation loop #183

Closed mjameson-se closed 11 months ago

mjameson-se commented 11 months ago

I had a bug in my code where I was creating a cancellation token with a zero timeout and passing this to an async lazy, which would promptly throw an OperationCancelledException as you might expect. However after many iterations of this, I started getting a different exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'function')
   at System.Threading.Tasks.Task.Run[TResult](Func`1 function, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Run[TResult](Func`1 function)
   at DotNext.Threading.AsyncLazy`1.GetOrStartAsync(CancellationToken token) in /_/src/DotNext.Threading/Threading/AsyncLazy.cs:line 101

This AsyncLazy was non-resettable, so I think its safe to assume the change has something to do with EraseFactory

sakno commented 11 months ago

Do you have repro code?