okio icon indicating copy to clipboard operation
okio copied to clipboard

Document behaviour of Okio on interrupts and Timeout on nonJvm platform

Open yschimke opened this issue 3 years ago • 1 comments

Apologies if there is already documentation on this. Two questions here.

  1. Timeouts on nonJvmMain?

It seems like commonMain Timeout suggests this is functional, but nonJvmMain doesn't have an implementation here.

https://github.com/square/okio/blob/5086d945ab5eebbe63d45a15ea9cc69197140d0a/okio/src/commonMain/kotlin/okio/Timeout.kt

  1. Also not clear how interrupts are supported throughout Okio.

From https://github.com/square/okio/blob/5086d945ab5eebbe63d45a15ea9cc69197140d0a/okio/src/jvmMain/kotlin/okio/Timeout.kt#L96 it's at least partially supported.

But what happens when the IO operation throws an InterruptedIOException, it does not appear that bytesTransferred is considered at all, but not sure I'd trust it anyway (unless I was directly writing to the bottom layer e.g. Socket).

What is the state of a BufferedSink after an InterruptedIOException?

internal inline fun RealBufferedSink.commonWrite(source: Buffer, byteCount: Long) {
  check(!closed) { "closed" }
  buffer.write(source, byteCount)
  emitCompleteSegments()
}

yschimke avatar Jan 23 '22 13:01 yschimke

After any IOException the streams must be discarded: there's no recovering.

Timeouts? We're mostly stuck waiting for the new Kotlin/Native memory model, at which point we should be able to do AsyncTimeout on Native safely.

swankjesse avatar Jan 29 '22 11:01 swankjesse