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

Commit

Permalink
Fix CancellationTokenRegistration.Token after CTS.Dispose (#21417)
Browse files Browse the repository at this point in the history
CTR.Token should never throw, but it's currently throwing an ObjectDisposedException if the associated CancellationTokenSource has been disposed.
  • Loading branch information
stephentoub authored Dec 7, 2018
1 parent 35da0c5 commit b24eee8
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public void Dispose()
/// registration isn't associated with a token (such as after the registration has been disposed),
/// this will return a default token.
/// </summary>
public CancellationToken Token => _node?.Partition.Source.Token ?? default(CancellationToken);
public CancellationToken Token
{
get
{
CancellationTokenSource.CallbackNode node = _node;
return node != null ?
new CancellationToken(node.Partition.Source) : // avoid CTS.Token, which throws after disposal
default;
}
}

/// <summary>
/// Disposes of the registration and unregisters the target callback from the associated
Expand Down

0 comments on commit b24eee8

Please sign in to comment.