Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Nov 26, 2019

Port dotnet/runtime#309 to release/3.1
Fixes https://github.com/dotnet/coreclr/issues/22946

Description

If multiple threads race to Unregister and zero out a CancellationTokenRegistration field, we can end up null ref'ing due to a torn read/write on a struct resulting in passing around some inconsistent state. This pattern is possible as part of clean up in Task.Delay(timeout, cancellationToken), with the null ref then happening on a thread pool thread that results in the app crashing.

Customer Impact

Valid coding patterns, both in customer code and in our framework implementation, resulting in NullReferenceExceptions that may not be catchable. Back in March a customer reported this, and just recently @rynowak hit up against it in ASP.NET.

Regression?

Yes, from .NET Framework 4.8 and .NET Core 2.0. This was introduced in #12819 in 2.1 as part of overhauling the CancellationToken implementation.

Testing

Isolated a repro that quickly fails (within a second) prior to the fix and successfully runs for a long time after.

Risk

Minimal.

cc: @tarekgh, @kouvel, @rynowak

@danmosemsft

@stephentoub stephentoub added this to the 3.1.1 milestone Nov 26, 2019
@stephentoub stephentoub added the Servicing-consider Issue for next servicing release review label Nov 26, 2019
@maryamariyan maryamariyan added area-System.Threading Servicing-consider Issue for next servicing release review and removed Servicing-consider Issue for next servicing release review labels Dec 4, 2019
@leecow leecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Dec 5, 2019
@leecow leecow modified the milestones: 3.1.1, 3.1.2 Dec 5, 2019
@vivmishra
Copy link

Moved to Mar as per Tactics. Will need to be explicitly approved for Feb, if required.

@vivmishra vivmishra modified the milestones: 3.1.2, 3.1.3 Jan 9, 2020
@jeffschwMSFT jeffschwMSFT modified the milestones: 3.1.3, 3.1.2 Jan 14, 2020
@jeffschwMSFT
Copy link
Member

Approved for Feb

@Anipik Anipik merged commit 1e0eabe into dotnet:release/3.1 Jan 14, 2020
@stephentoub stephentoub deleted the port309 branch April 17, 2020 20:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Threading Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants