Skip to content

Allow fire and forget CancellationTokenRegisteration.Dispose #19827

@davidfowl

Description

@davidfowl

Right now disposing a CancellationTokenRegistration will wait for pending callbacks to run if it's disposed on a separate thread from the callback itself. This can cause deadlocks for e.g.:

aspnet/KestrelHttpServer#1278

It would be nice to have a way to disable the blocking on dispose. It might require an API change.

/cc @stephentoub


EDIT 6/29/2018 from stephentoub:
This is the proposed method to be added to CancellationTokenRegistration:

public struct CancellationTokenRegistration
{
    public bool Unregister();
    ...
}

We can separately have a discussion about adding a DisposeAsync when the corresponding interface comes along, but we know we can use this API and use it now (it's already there, just not public), and it has a different purpose than a DisposeAsync would. The semantics here are simply that whereas Dispose unregisters and then if the callback is currently running waits for it, this API just unregisters.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions