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,