@@ -17,13 +17,14 @@ import org.springframework.http.HttpStatus
1717import org.springframework.http.ResponseEntity
1818import org.springframework.web.bind.annotation.*
1919import org.springframework.web.server.ResponseStatusException
20+ import java.util.concurrent.TimeUnit
2021
2122@RestController
2223class PlayerRestHandler (
2324 private val socketServer : SocketServer ,
2425 private val filterExtensions : List <AudioFilterExtension >,
2526 private val pluginInfoModifiers : List <AudioPluginInfoModifier >,
26- serverConfig : ServerConfig ,
27+ private val serverConfig : ServerConfig ,
2728 private val searchMetrics : SearchMetrics ? = null
2829) {
2930
@@ -127,16 +128,18 @@ class PlayerRestHandler(
127128 context.koe.destroyConnection(guildId)
128129
129130 val conn = context.getMediaConnection(player)
131+ val timeout = serverConfig.timeouts?.connectTimeoutMs?.toLong() ? : 3000
130132 conn.connect(
131133 VoiceServerInfo .builder()
132134 .setSessionId(it.sessionId)
133135 .setEndpoint(it.endpoint)
134136 .setToken(it.token)
135137 .setChannelId(it.channelId!! .toLong())
136138 .build()
137- ).exceptionally {
139+ ).toCompletableFuture().orTimeout(timeout, TimeUnit .MILLISECONDS ).exceptionally {
140+ context.koe.destroyConnection(guildId)
138141 throw ResponseStatusException (HttpStatus .INTERNAL_SERVER_ERROR , " Failed to connect to voice server" )
139- }.toCompletableFuture(). join()
142+ }.join()
140143 player.provideTo(conn)
141144 }
142145 }
@@ -240,5 +243,3 @@ class PlayerRestHandler(
240243 socketContext(socketServer, sessionId).destroyPlayer(guildId)
241244 }
242245}
243-
244-
0 commit comments