Skip to content

Commit 6d91be8

Browse files
committed
Explain benign data-race on SelectImplementation.internalResult and mark it with @BenignDataRace
Fixes #3843
1 parent 3e5acfd commit 6d91be8

File tree

1 file changed

+6
-3
lines changed
  • kotlinx-coroutines-core/common/src/selects

1 file changed

+6
-3
lines changed

kotlinx-coroutines-core/common/src/selects/Select.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ internal open class SelectImplementation<R>(
413413
* or [DisposableHandle] instance when the clause is completed during registration ([inRegistrationPhase] is `false`).
414414
* Yet, this optimization is omitted for code simplicity.
415415
*/
416+
@BenignDataRace // See its cleanup phase for the explanation
416417
private var internalResult: Any? = NO_RESULT
417418

418419
/**
@@ -626,9 +627,11 @@ internal open class SelectImplementation<R>(
626627
// try to resume the continuation.
627628
this.internalResult = internalResult
628629
if (cont.tryResume(onCancellation)) return TRY_SELECT_SUCCESSFUL
629-
// If the resumption failed, we need to clean
630-
// the [result] field to avoid memory leaks.
631-
this.internalResult = null
630+
/*
631+
* If the resumption failed, we need to clean the [result] field to avoid memory leaks.
632+
* This write is benignly races with the very same write in cancellation invoke() handler
633+
*/
634+
this.internalResult = NO_RESULT
632635
return TRY_SELECT_CANCELLED
633636
}
634637
}

0 commit comments

Comments
 (0)