kotlinx-io
kotlinx-io copied to clipboard
Getting buffer overflow randomly in tests
I am getting
java.nio.BufferOverflowException
at java.base/java.nio.Buffer.nextPutIndex(Buffer.java:662)
at java.base/java.nio.HeapByteBuffer.put(HeapByteBuffer.java:196)
at kotlinx.io.core.IoBuffer.writeByte(IoBufferJVM.kt:164)
at kotlinx.io.core.BytePacketBuilderBase.writeByte(Builder.kt:436)
in tests when I run a lot of tests simultaniously. When I run them individually, everything works fine. I tried to debug the problem, but it proved to be rather hard due to not always obvious borrowing logic. There is a check inside that should prevent this error, but is does not seem to work.
It seems that the problem is caused by the fact that IOBuffers created by ByteReadPacket(array) (which have the wrong size) are randomly being disposed into default pool and then reused. I think it should be fixed in io-2.
We're rebooting the kotlinx-io development (see https://github.com/Kotlin/kotlinx-io/issues/131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version.