kordlib/Lavalink.kt

Websocket connection errors are not being handled correctly on Kotlin/JS

DRSchlaubi opened this issue · 0 comments

Currently, whenever an error occurs in the WebSocket connection the following JS error is being printed and kills the nodejs process

      var exception = new WebSocketException(JSON.stringify(event));
                                                  ^
TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Socket'
    |     property 'parser' -> object with constructor 'HTTPParser'
    --- property 'socket' closes the circle
    at JSON.stringify (<anonymous>)
    at WebSocket.<anonymous> (D:\WORK\lavakord\build\js\node_modules\ktor-ktor-client-core-jsLegacy\ktor-ktor-client-core-jsLegacy.js:17440:51)
    at WebSocket.onError (D:\WORK\lavakord\build\js\node_modules\ws\lib\event-target.js:128:16)
    at WebSocket.emit (events.js:311:20)
    at abortHandshake (D:\WORK\lavakord\build\js\node_modules\ws\lib\websocket.js:718:15)
    at ClientRequest.<anonymous> (D:\WORK\lavakord\build\js\node_modules\ws\lib\websocket.js:595:7)
    at ClientRequest.emit (events.js:311:20)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:603:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
    at Socket.socketOnData (_http_client.js:476:22)```

As this error gets thrown whilst Ktor is trying to turn the JS Error into a Ktor exception Lavakord cannot catch it. This also prevents Lavakord from reconnecting and resuming the connection

I created a Ktor issue here: https://youtrack.jetbrains.com/issue/KTOR-1726

Edit 1: Reconnecting works when the client is able to reconnect on the 1st try, but as soon as an exception has to be handled KTOR throws a javascript error which kills the whole process