From 1a2bf65cc3f9a3c87e5d3a2ae5e74a95ae7e4491 Mon Sep 17 00:00:00 2001 From: Nikita Koval Date: Mon, 1 May 2023 14:01:52 +0200 Subject: [PATCH] Fix non-linearizability in `BufferedChannel.expandBuffer()` Signed-off-by: Nikita Koval --- .../common/src/channels/BufferedChannel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt b/kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt index edb1c3c9f7..b749ee63f8 100644 --- a/kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt +++ b/kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt @@ -1220,9 +1220,9 @@ internal open class BufferedChannel( incCompletedExpandBufferAttempts() return } - // Is `bufferEndSegment` outdated? + // Is `bufferEndSegment` outdated or is the segment with the required id already removed? // Find the required segment, creating new ones if needed. - if (segment.id < id) { + if (segment.id != id) { segment = findSegmentBufferEnd(id, segment, b) // Restart if the required segment is removed, or // the linked list of segments is already closed,