Skip to content

Commit deb3372

Browse files
authored
KTOR-2519 fix ByteBufferChannel.readRemaining suspend when should not (#2434)
1 parent b7b342d commit deb3372

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ktor-io/common/test/io/ktor/utils/io/ByteChannelSmokeTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,14 @@ open class ByteChannelSmokeTest : ByteChannelTestBase() {
662662
assertFailsWith<IOException> { ch.readByte() }
663663
}
664664

665+
@Test
666+
fun testReadRemainingAvailable() = runTest {
667+
ch.writeFully(byteArrayOf(1, 2, 3))
668+
ch.flush()
669+
val remaining = ch.readRemaining(3).remaining
670+
assertEquals(3, remaining)
671+
}
672+
665673
private fun assertEquals(expected: Float, actual: Float) {
666674
if (abs(expected - actual) > 0.000001f) {
667675
kotlin.test.assertEquals(expected, actual)

ktor-io/jvm/src/io/ktor/utils/io/ByteBufferChannel.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,8 +2153,7 @@ internal open class ByteBufferChannel(
21532153

21542154
val rc = readAsMuchAsPossible(buffer)
21552155
remaining -= rc
2156-
readSuspend(1)
2157-
remaining > 0L && !isClosedForRead
2156+
remaining > 0L && !isClosedForRead && readSuspend(1)
21582157
}
21592158

21602159
closedCause?.let { throw it }

0 commit comments

Comments
 (0)