https://kotlinlang.org logo
#ktor
Title
# ktor
n

Nikky

05/19/2021, 5:01 PM
we have some weird issue with websocket sessions on kotlinJS when we try to close them.. they stop getting used.. but the connection seems to stay open and the backend only reports on it getting closed when the tab gets refreshed or browser closed what i randomly found.. these calls close it properly
Copy code
public suspend fun closeSession() {
        // we don't know why this magic is necessary
        session?.close()
        session?.close(CloseReason(CloseReason.Codes.GOING_AWAY,"Logging out"))
        session?.closeReason?.await()
    }
but i don't really know why.. and any other order or leaving any of them out seems to not do it properly anymore could also be something in our spring-webflux backend.. i guess
c

cy

05/20/2021, 10:20 AM
Do you see any errors in the browser dev console? Once one send a close frame, the backend closes websocket object. On JS we don’t control connections so it’s up to browser, when to close them, but I believe sending close frame should cause close sequence to begin and the connection should be closed. How do you know that the connection is still alive? Can you debug the server-side to see if it gets a close frame?
n

Nikky

05/20/2021, 12:55 PM
i tested with the server running locally.. the server has a logging statement in a try-finally block in only one case it directly cancelled the websocket serverside i did not see any errors in the console (tested in firefox and google-chrome)
i do not see a close event being sent in the browser devtools either and it reports that the request is ongoing...

https://nikky.catgirl.host/i/t2org0zu.png

(although the times it reports do not update either)
.. that is when i just call
session.close()
when i do the 3 weird calls in the right order.. thge orange warning
CAUTION: request is ongoing
disappears although i still do not see a close frame in the messages tab.. so maybe it just does not show
2 Views