Skip to content

Commit

Permalink
add support to override default request timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Dec 7, 2024
1 parent 278bc91 commit 68c47ab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions LavalinkServer/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ lavalink:
#proxyPort: 3128 # Proxy port, 3128 is the default for squidProxy
#proxyUser: "" # Optional user for basic authentication fields, leave blank if you don't use basic auth
#proxyPassword: "" # Password for basic authentication
timeouts:
connectTimeoutMs: 3000
connectionRequestTimeoutMs: 3000
socketTimeoutMs: 3000

metrics:
prometheus:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.sedmelluq.discord.lavaplayer.source.soundcloud.*
import com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioSourceManager
import com.sedmelluq.discord.lavaplayer.source.vimeo.VimeoAudioSourceManager
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager
import com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools
import com.sedmelluq.discord.lavaplayer.track.playback.NonAllocatingAudioFrameBuffer
import com.sedmelluq.lava.extensions.youtuberotator.YoutubeIpRotatorSetup
import com.sedmelluq.lava.extensions.youtuberotator.planner.*
Expand All @@ -24,6 +25,8 @@ import org.apache.http.HttpHost
import org.apache.http.auth.AuthScope
import org.apache.http.auth.UsernamePasswordCredentials
import org.apache.http.client.CredentialsProvider
import org.apache.http.client.config.CookieSpecs
import org.apache.http.client.config.RequestConfig
import org.apache.http.impl.client.BasicCredentialsProvider
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Bean
Expand All @@ -50,6 +53,26 @@ class AudioPlayerConfiguration {
audioPlayerManagerConfigurations: Collection<AudioPlayerManagerConfiguration>,
mediaContainerProbes: Collection<MediaContainerProbe>
): AudioPlayerManager {
serverConfig.timeouts?.let {
HttpClientTools.setDefaultRequestConfig(
RequestConfig.custom()
.setConnectTimeout(3000)
.setConnectionRequestTimeout(3000)
.setSocketTimeout(3000)
.setCookieSpec(CookieSpecs.STANDARD)
.build()
)

HttpClientTools.setNoCookiesRequestConfig(
RequestConfig.custom()
.setConnectTimeout(3000)
.setConnectionRequestTimeout(3000)
.setSocketTimeout(3000)
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.build()
)
}

val audioPlayerManager = DefaultAudioPlayerManager()

if (serverConfig.isGcWarnings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ class ServerConfig {
var youtubeConfig: YoutubeConfig? = null
var httpConfig: HttpConfig? = null
var filters: Map<String, Boolean> = mapOf()
var timeouts: TimeoutsConfig? = null
}

class TimeoutsConfig {
var connectTimeoutMs: Int = 3000
var connectionRequestTimeoutMs: Int = 3000
var socketTimeoutMs: Int = 3000
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ allprojects {
mavenLocal() // useful for developing
maven("https://m2.dv8tion.net/releases")
maven("https://maven.lavalink.dev/releases")
maven("https://maven.lavalink.dev/snapshots")
jcenter()
maven("https://jitpack.io") // build projects directly from GitHub
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun VersionCatalogBuilder.spring() {
}

fun VersionCatalogBuilder.voice() {
version("lavaplayer", "2.2.2")
version("lavaplayer", "a099a98b55e33c1694b2e2636ecd1c3a33769707-SNAPSHOT")
version("koe", "2.0.3-rc2")

library("lavaplayer", "dev.arbjerg", "lavaplayer").versionRef("lavaplayer")
Expand Down

0 comments on commit 68c47ab

Please sign in to comment.