Lavalink.kt icon indicating copy to clipboard operation
Lavalink.kt copied to clipboard

Nodes do not attempt reconnecting after initial connection refused

Open freyacodes opened this issue 2 years ago • 2 comments

After calling Lavakord.addNode() and encountering a refused connection, this exception is raised:

Exception in thread "DefaultDispatcher-worker-9" java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:673)
	at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:973)
	at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:50)
	at io.ktor.network.sockets.SocketImpl$connect$1.invokeSuspend(SocketImpl.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)

The coroutine then ends without retrying, as retries are only done when ReconnectException is caught.

java.net.ConnectException is JVM specific, so I am unsure how to catch it in multiplatform code

freyacodes avatar Oct 16 '23 14:10 freyacodes

https://github.com/kordlib/Lavalink.kt/blob/21db0f3b9811b665c6bb65786454b8313909d221/core/src/jvmMain/kotlin/dev/schlaubi/lavakord/audio/internal/Platform.kt#L28-L30

That should be cought

DRSchlaubi avatar Oct 16 '23 17:10 DRSchlaubi

Upon closer inspection, the problem is caused by the exception being thrown by check(), which has no fault tolerance.

I'm very tempted to just wrap a try/catch around check() for Exception

freyacodes avatar Oct 17 '23 08:10 freyacodes