This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
src/System.Private.CoreLib/shared/System/Threading Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -524,6 +524,7 @@ internal CancellationTokenRegistration InternalRegister(
524
524
{
525
525
// Assign the next available unique ID.
526
526
id = partition . NextAvailableId ++ ;
527
+ Debug . Assert ( id != 0 , "IDs should never be the reserved value 0." ) ;
527
528
528
529
// Get a node, from the free list if possible or else a new one.
529
530
node = partition . FreeNodeList ;
@@ -942,9 +943,16 @@ public CallbackPartition(CancellationTokenSource source)
942
943
943
944
internal bool Unregister ( long id , CallbackNode node )
944
945
{
945
- Debug . Assert ( id != 0 , "Expected non-zero id" ) ;
946
946
Debug . Assert ( node != null , "Expected non-null node" ) ;
947
947
948
+ if ( id == 0 )
949
+ {
950
+ // In general, we won't get 0 passed in here. However, race conditions between threads
951
+ // Unregistering and also zero'ing out the CancellationTokenRegistration could cause 0
952
+ // to be passed in here, in which case there's nothing to do. 0 is never a valid id.
953
+ return false ;
954
+ }
955
+
948
956
bool lockTaken = false ;
949
957
Lock . Enter ( ref lockTaken ) ;
950
958
try
You can’t perform that action at this time.
0 commit comments