Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow overriding default request timeouts #1117

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(it.connectTimeoutMs)
.setConnectionRequestTimeout(it.connectionRequestTimeoutMs)
.setSocketTimeout(it.socketTimeoutMs)
.setCookieSpec(CookieSpecs.STANDARD)
.build()
)

HttpClientTools.setNoCookiesRequestConfig(
RequestConfig.custom()
.setConnectTimeout(it.connectTimeoutMs)
.setConnectionRequestTimeout(it.connectionRequestTimeoutMs)
.setSocketTimeout(it.socketTimeoutMs)
.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
Loading