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

mbonnin

10/25/2023, 1:31 PM
Using
ktor-network
, is it possible to force close a
ServerSocket
that has active connections? I can get it to work on the JVM but
SocketServer.close()
hangs on
macosArm64
.
The gist of it is
Copy code
val selectorManager = SelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)
            val serverSocket = aSocket(selectorManager).tcp().bind("127.0.0.1", port)

            launch {
                val socket = serverSocket.accept()

                launch {
                    delay(15.seconds)
                    socket.close()
                    // hangs here
                    serverSocket.close()
                }

                socket.openReadChannel().readInt()
            }
e

e5l

10/25/2023, 1:32 PM
Hey @mbonnin, could you try cancelling it?
m

mbonnin

10/25/2023, 1:32 PM
trying now!
Mmm, I don't have a
serverSocket.cancel()
, do you mean cancelling the scope?
👍 1
Or just
socket.cancel()
? (trying now... but same thing)
Cancelling the scope is what I did initially but this seemed to keep the port & active sockets alive, which I don't want.
e

e5l

10/25/2023, 1:36 PM
It shouldn't be a case. Could you log an issue with a sample? I will take a look
👍 1
m

mbonnin

10/25/2023, 1:36 PM
👍 sounds good, will try to reproduce
e

e5l

10/25/2023, 2:31 PM
Thanks, will check
💙 2
2 Views