Edit: I was reading more bytes then available in the Node socket buffer, thus I was never completing the job
Anyone ever got a problem where a coroutine is just stuck at a return statement?
Copy code
private suspend fun readUnsignedInt(): Number {
val buffer = read(4) ?: throw IllegalStateException("Expected 4 bytes to be available")
val number = buffer.readUInt32BE(0)
println(number)
return number
}
I can see the number printed to the console, and then nothing, stuck forever.
a
Artem Kobzar
06/28/2023, 2:14 PM
Seems like a bug inside the Node.js wrappers. Could you please create a ticket in youtrack and assign it on me?
e
Edoardo Luppi
06/28/2023, 2:18 PM
@Artem Kobzar what was happening is this.
I'm reading n bytes from the TCP
net.Socket
Copy code
socket.read(nBytes)
If
nBytes
is greater than
socket.readableLength
,
read
returns null.
What I was doing was:
Copy code
val buffer = socket.read(nBytes) as? Buffer?
if (buffer != null) {
continuation.resume(buffer)
}
Are you sure it's a bug on your side? This seems more an error on my side