Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race with CancellableContinuationImpl.parentHandle #2660

Closed
shmuelr opened this issue Apr 20, 2021 · 1 comment
Closed

Data race with CancellableContinuationImpl.parentHandle #2660

shmuelr opened this issue Apr 20, 2021 · 1 comment
Assignees

Comments

@shmuelr
Copy link
Contributor

shmuelr commented Apr 20, 2021

Hey there,

Our internal Java TSAN tests inside Google picked up a race condition on the develop branch with CancellableContinuationImpl.parentHandle, likely introduced in this commit that changes parentHandle to be non-volatile.

According to our stack trace, the race happens at
line 494 parentHandle = NonDisposableHandle

WARNING: ThreadSanitizer: data race (pid=4318)
Write of size 4 at 0x0000cf6bf808 by thread T30 (mutexes: write M379709747054803224, write M380272697008225000, write M379709747035779072, write M380272696989200768, write M357473223960208968, write M361976823587580648, write M498773662268158696, write M565201756770664040):
#0 kotlinx.coroutines.CancellableContinuationImpl.detachChild$kotlinx_coroutines_kotlinx_coroutines()V CancellableContinuationImpl.kt:494
#1 kotlinx.coroutines.CancellableContinuationImpl.detachChildIfNonResuable()V CancellableContinuationImpl.kt:485
#2 kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(Ljava/lang/Object;ILkotlin/jvm/functions/Function1;)V CancellableContinuationImpl.kt:427
#3 kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(Lkotlinx/coroutines/CancellableContinuationImpl;Ljava/lang/Object;ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)V CancellableContinuationImpl.kt:420
#4 kotlinx.coroutines.CancellableContinuationImpl.resumeWith(Ljava/lang/Object;)V CancellableContinuationImpl.kt:325
#5 kotlinx.coroutines.guava.ToContinuation.run()V ListenableFuture.kt:266

Previous read of size 4 at 0x0000cf6bf808 by thread T9:
#0 kotlinx.coroutines.CancellableContinuationImpl.getResult()Ljava/lang/Object; CancellableContinuationImpl.kt:267
#1 kotlinx.coroutines.guava.ListenableFutureKt.await(Lcom/google/common/util/concurrent/ListenableFuture;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; ListenableFuture.kt:517
#2

It appears that parentHandle can be raced at when using ListenableFuture extensions for Coroutines, (possibly because LF calls getResult() which triggers the race at line 267).

Thanks!

@qwwdfsad qwwdfsad self-assigned this Apr 20, 2021
qwwdfsad added a commit that referenced this issue Apr 20, 2021
@qwwdfsad
Copy link
Member

Thanks for the report, good to know our code is externally tested for data-races :)

It is benign data-race and it's safe to suppress, I've added the corresponding comment

qwwdfsad added a commit that referenced this issue Apr 21, 2021
This was referenced Apr 13, 2022
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants