Skip to content

Fix NullReferenceException in Timer disposal - #5321

Merged
RussKie merged 2 commits into
dotnet:mainfrom
martincostello:gh-5316
Aug 2, 2024
Merged

RussKie merged 2 commits into
dotnet:mainfrom
martincostello:gh-5316

Conversation

@martincostello

@martincostello martincostello commented Jul 31, 2024 •

Copy link
Copy Markdown
Member

Protect against NullReferenceException when disposing of Timer.

Resolves #5316.

Microsoft Reviewers: Open in CodeFlow

Protect against `NullReferenceException` when disposing of `Timer`.
Resolves dotnet#5316.
@sebastienros

Copy link
Copy Markdown
Member

Looks like there could be the same kind of exception in the Change() method if the timer is disposed while another thread is disposing it.

a- The _timeProvider could also be locally assigned
b- The Change method could null-check it on each call.

Address similar null races in `Timer.Change()` too.
@RussKie
RussKie merged commit 68a79b5 into dotnet:main Aug 2, 2024
@RussKie

RussKie commented Aug 2, 2024

Copy link
Copy Markdown
Contributor

Thank you

@martincostello
martincostello deleted the gh-5316 branch August 2, 2024 06:09
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException in Timer.Dispose()

4 participants