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

Fix NullReferenceException in Timer disposal #5321

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

martincostello
Copy link
Member

@martincostello martincostello commented Jul 31, 2024

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
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
6 checks passed
@RussKie
Copy link
Member

RussKie commented Aug 2, 2024

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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullReferenceException in Timer.Dispose()
4 participants