korlibs-archive / korio

Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3

Home Page:https://korlibs.soywiz.com/korio/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSocket: exception reading close response

ArtRoman opened this issue · comments

Close response issue as described in #88. Checked on korio 1.11.10.
When I call websocket.close(), my websocket server responds with Close message with same status, but without any description, code only.

Websocket Close message can have code (short) and reason (string). Korio tries to read payload for every message type, even if payload is not used by korio for Close message. It fails with next exception, triggering onError after onClose:

java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
	at com.soywiz.korio.lang.UTC8CharsetBase.decode(Charset.kt:64)
	at com.soywiz.korio.lang.Charset.decode$default(Charset.kt:9)
	at com.soywiz.korio.lang.CharsetKt.toString(Charset.kt:145)
	at com.soywiz.korio.net.ws.RawSocketWebSocketClient.internalReadPackets(RawSocketWebSocketClient.kt:141)
	at com.soywiz.korio.net.ws.RawSocketWebSocketClient$internalReadPackets$1.invokeSuspend(RawSocketWebSocketClient.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)