ChannelWriteStream closes the underlying stream too early
Version
Vert.x 4.4.5
Context
When you call ChannelWriteStream#close the underlying stream gets closed immediately whereas the channel might still have an item or two in it and the job reading from the channel has the opportunity to complete them and in fact is still running and might encounter the closed stream
To illustrate the point, consider the following changes:
ChannelWriteStream#close just needs to close the channel
override fun close(cause: Throwable?): Boolean {
return channel.close(cause)
}
The reading job should close the stream instead when the channel is closed, all the remaining items are received and you exit the loop. The suggested change is to use try-finally over the original code and close the stream in the finally block.
launch {
try {
while (true) {
val res = channel.receiveCatching()
....
}
} finally {
stream.end()
}
}
### Do you have a reproducer?
No, because it's a race condition.
Questions
ChannelWriteStream
closes the underlying stream too earlyVersion
Vert.x 4.4.5
Context
When you call ChannelWriteStream#close the underlying stream gets closed immediately whereas the channel might still have an item or two in it and the job reading from the channel has the opportunity to complete them and in fact is still running and might encounter the closed stream
To illustrate the point, consider the following changes:
ChannelWriteStream#close
just needs to close the channel