Skip to content

NullReferenceException in Timer.Dispose() #5316

Description

@martincostello

Description

I couldn't re-open #4985 as it's locked, but this issue just occurred again in a different test: #4985 (comment)

Logs

  Failed Polly.Core.Tests.Issues.IssuesTests.InfiniteRetry_Delay_Does_Not_Overflow_2163 [34 ms]
  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at Microsoft.Extensions.Time.Testing.Timer.Dispose()
   at System.Threading.Tasks.TimeProviderTaskExtensions.Delay(TimeProvider timeProvider, TimeSpan delay, CancellationToken cancellationToken)
   at Polly.Utils.TimeProviderExtensions.DelayAsync(TimeProvider timeProvider, TimeSpan delay, ResilienceContext context) in /_/src/Polly.Core/Utils/TimeProviderExtensions.cs:line 45
   at Polly.Retry.RetryResilienceStrategy`1.<ExecuteCore>d__28`1.MoveNext() in /_/src/Polly.Core/Retry/RetryResilienceStrategy.cs:line 98
--- 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 Polly.Utils.Pipeline.BridgeComponent`1.<<ConvertValueTask>g__ConvertValueTaskAsync|5_0>d`1.MoveNext() in /_/src/Polly.Core/Utils/Pipeline/BridgeComponent.TResult.cs:line 51
--- 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 Polly.ResiliencePipeline.<ExecuteAsync>d__10`1.MoveNext() in /_/src/Polly.Core/ResiliencePipeline.AsyncT.cs:line 170
--- 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 Polly.Core.Tests.Issues.IssuesTests.<InfiniteRetry_Delay_Does_Not_Overflow_2163>d__7.MoveNext() in /_/test/Polly.Core.Tests/Issues/IssuesTests.InfiniteRetry_2163.cs:line 54
--- 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)
--- 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)
--- 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)

Reproduction Steps

Run the InfiniteRetry_Delay_Does_Not_Overflow_2163 test in the Polly code base many many times (this is the first occurrence for about 5 months). Eventually, you'll probably get the right timing to hit the bug.

Expected behavior

A NullReferenceException does not occur.

Actual behavior

A NullReferenceException is thrown from trying to dispose a null reference.

Regression?

Probably not and has been an issue since the first stable release of the TimeProvider testing extensions.

Known Workarounds

None.

Configuration

.NET SDK 8.0.303 and Microsoft.Extensions.TimeProvider.Testing version 8.7.0.

Other information

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions