Aborting read on Pipe
nicolashaan opened this issue · comments
nicolashaan commented
Hi all,
The following source is blocking indefinitely on the readByte()
line.
I expected the close()
call to unlock the read call by throwing an IOException
.
Is this the intended behavior?
Is there a way to unlock a blocking read call?
fun `Pipe playground`() {
val pipe = Pipe(1024)
val bufferedSource = pipe.source.buffer()
thread {
Thread.sleep(1000)
println("Closing source...")
bufferedSource.close()
println("Source closed")
}
println("Before read()")
val out = bufferedSource.readByte()
println("After read()")
}
output:
Before read()
Closing source...
Source closed
Thanks!
Jesse Wilson commented
No Okio streams are safe for concurrent use, including calls to close() that coincide with other operations.
The function you want is Pipe.cancel(). It had the side-effects you’re looking for.
https://square.github.io/okio/3.x/okio/okio/okio/-pipe/cancel.html