consumeEachBufferRange completes successfully on connection abort
- Dominant language
- Kotlin
- Stars
- 14.5k
- Forks
- 1.3k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 49
Description
**Ktor Version and Engine Used**
Ktor Client 1.3.2 with OkHttpClient 4.5.0 on Android 21
**Describe the bug**
When the connection dies during a streaming download, `consumeEachBufferRange` erroneously completes successfully.
**To Reproduce**
1. I'm streaming a download using `consumeEachBufferRange`.
2. When I turn on Airplane Mode during the download, the `visitor` I've passed to `consumeEachBufferRange` will be called with a `buffer` object that has `0` remaining bytes and `last` set to `true`. The latter, to my knowledge, indicates download completion.
4. No `IOException` is thrown which further indicates that the download has completed.
4. The download (`consumeEachBufferRange` invocations) isn't even close to the number of bytes indicated in the `Content-Length` header.
Note that it doesn't happen 100% of the time.
Sometimes I do get a shorter packet (e.g. 64 bytes instead of a typical 4088 byte packet) with `last = false` plus a `SocketTimeoutException` afterwards.
**Expected behavior**
- `consumeEachBufferRange` shouldn't be called with a `0` byte buffer.
- `consumeEachBufferRange` shouldn't be called with `last = true` for an aborted connection.
- `consumeEachBufferRange` should throw an `IOException` for an aborted connection.
Contributor guide
Assessment
This issue has not been assessed yet.