From 61655331824924d4de4db4d2c872d99ad143c1ae Mon Sep 17 00:00:00 2001 From: Nikita Koval Date: Fri, 5 May 2023 15:18:24 +0200 Subject: [PATCH] Fix non-linearizability in `BufferedChannel.expandBuffer()` (#3730) 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,