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

Lock when reading a ConflatedChannel's value. #3248

Merged
merged 1 commit into from
Apr 12, 2022
Merged

Conversation

mpetrov
Copy link
Contributor

@mpetrov mpetrov commented Apr 11, 2022

Reads in isBufferEmpty() were detected as a race by internal tests.

See #2660 for a similar TSAN-flagged issue.

A snippet of the race found is below:

  Read of size 4 at 0x0000cf809644 by thread T10 (mutexes: write M0, write M1):
    #0 kotlinx.coroutines.channels.ConflatedChannel.isBufferEmpty()Z ConflatedChannel.kt:22
  Previous write of size 4 at 0x0000cf809644 by thread T32 (mutexes: write M2, write M3, write M4, write M5, write M6, write M7):
    #0 kotlinx.coroutines.channels.ConflatedChannel.updateValueLocked(Ljava/lang/Object;)Lkotlinx/coroutines/internal/UndeliveredElementException; ConflatedChannel.kt:131

Reads in `isBufferEmpty()` were detected as a race by internal tests.

The relevant stack snippets are:

```
  Read of size 4 at 0x0000cf809644 by thread T10 (mutexes: write M0, write M1):
    #0 kotlinx.coroutines.channels.ConflatedChannel.isBufferEmpty()Z ConflatedChannel.kt:22
```

and:

```
  Previous write of size 4 at 0x0000cf809644 by thread T32 (mutexes: write M2, write M3, write M4, write M5, write M6, write M7):
    #0 kotlinx.coroutines.channels.ConflatedChannel.updateValueLocked(Ljava/lang/Object;)Lkotlinx/coroutines/internal/UndeliveredElementException; ConflatedChannel.kt:131
```
@qwwdfsad qwwdfsad self-requested a review April 12, 2022 09:58
Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

@qwwdfsad qwwdfsad merged commit 52cbf01 into Kotlin:master Apr 12, 2022
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this pull request Sep 14, 2022
Reads in `isBufferEmpty()` were detected as a race by internal tests.

The relevant stack snippets are:

```
  Read of size 4 at 0x0000cf809644 by thread T10 (mutexes: write M0, write M1):
    #0 kotlinx.coroutines.channels.ConflatedChannel.isBufferEmpty()Z ConflatedChannel.kt:22
```

and:

```
  Previous write of size 4 at 0x0000cf809644 by thread T32 (mutexes: write M2, write M3, write M4, write M5, write M6, write M7):
    #0 kotlinx.coroutines.channels.ConflatedChannel.updateValueLocked(Ljava/lang/Object;)Lkotlinx/coroutines/internal/UndeliveredElementException; ConflatedChannel.kt:131
```
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

Successfully merging this pull request may close these issues.

2 participants