Fix #571:make timeout configurable and bump default to 15 sec
This commit is contained in:
+2
-1
@@ -148,7 +148,8 @@ func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleas
|
||||
_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
||||
})
|
||||
if a.Config.Application.EnableLrcLib {
|
||||
a.LrcLibFetcher = NewLrcLibFetcher(a.cacheDir, a.Config.Application.CustomLrcLibUrl)
|
||||
timeout := time.Duration(a.Config.Application.RequestTimeoutSeconds) * time.Second
|
||||
a.LrcLibFetcher = NewLrcLibFetcher(a.cacheDir, a.Config.Application.CustomLrcLibUrl, timeout)
|
||||
}
|
||||
|
||||
a.PlaybackManager.OnPlaying(func() {
|
||||
|
||||
+2
-1
@@ -54,8 +54,8 @@ type AppConfig struct {
|
||||
Language string
|
||||
DisableDPIDetection bool
|
||||
EnableAutoUpdateChecker bool
|
||||
RequestTimeoutSeconds int
|
||||
|
||||
// Experimental - may be removed in future
|
||||
FontNormalTTF string
|
||||
FontBoldTTF string
|
||||
UIScaleSize string
|
||||
@@ -191,6 +191,7 @@ func DefaultConfig(appVersionTag string) *Config {
|
||||
EnqueueBatchSize: 100,
|
||||
Language: "auto",
|
||||
EnableAutoUpdateChecker: true,
|
||||
RequestTimeoutSeconds: 15,
|
||||
},
|
||||
AlbumPage: AlbumPageConfig{
|
||||
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},
|
||||
|
||||
+4
-3
@@ -26,12 +26,13 @@ const lrclibCacheFolder = "lrclib"
|
||||
type LrcLibFetcher struct {
|
||||
cachePath string
|
||||
customLrcLibUrl string
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func NewLrcLibFetcher(baseCacheDir string, customLrcLibUrl string) *LrcLibFetcher {
|
||||
func NewLrcLibFetcher(baseCacheDir string, customLrcLibUrl string, timeout time.Duration) *LrcLibFetcher {
|
||||
cachePath := filepath.Join(baseCacheDir, lrclibCacheFolder)
|
||||
configdir.MakePath(cachePath)
|
||||
return &LrcLibFetcher{cachePath: cachePath, customLrcLibUrl: customLrcLibUrl}
|
||||
return &LrcLibFetcher{cachePath: cachePath, customLrcLibUrl: customLrcLibUrl, timeout: timeout}
|
||||
}
|
||||
|
||||
func (l *LrcLibFetcher) FetchLrcLibLyrics(name, artist, album string, durationSecs int) (*mediaprovider.Lyrics, error) {
|
||||
@@ -67,7 +68,7 @@ func (l *LrcLibFetcher) FetchLrcLibLyrics(name, artist, album string, durationSe
|
||||
}
|
||||
|
||||
func (l *LrcLibFetcher) fetchFromServer(name, artist, album string, durationSecs int) (*mediaprovider.Lyrics, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), l.timeout)
|
||||
defer cancel()
|
||||
|
||||
lrclibUrl := l.getLrclibUrl()
|
||||
|
||||
@@ -177,9 +177,10 @@ func (s *ServerManager) SetServerPassword(server *ServerConfig, password string)
|
||||
|
||||
func (s *ServerManager) connect(connection ServerConnection, password string) (mediaprovider.Server, error) {
|
||||
var cli, altCli mediaprovider.Server
|
||||
timeout := time.Second * time.Duration(s.config.Application.RequestTimeoutSeconds)
|
||||
|
||||
if connection.ServerType == ServerTypeJellyfin {
|
||||
client, err := jellyfin.NewClient(connection.Hostname, res.AppName, res.AppVersion, jellyfin.WithTimeout(10*time.Second))
|
||||
client, err := jellyfin.NewClient(connection.Hostname, res.AppName, res.AppVersion, jellyfin.WithTimeout(timeout))
|
||||
if err != nil {
|
||||
log.Printf("error creating Jellyfin client: %s", err.Error())
|
||||
return nil, err
|
||||
@@ -190,7 +191,7 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
||||
}
|
||||
|
||||
if connection.AltHostname != "" {
|
||||
altClient, err := jellyfin.NewClient(connection.AltHostname, res.AppName, res.AppVersion, jellyfin.WithTimeout(10*time.Second))
|
||||
altClient, err := jellyfin.NewClient(connection.AltHostname, res.AppName, res.AppVersion, jellyfin.WithTimeout(timeout))
|
||||
if err != nil {
|
||||
log.Printf("error creating Jellyfin alternative client: %s", err.Error())
|
||||
return nil, err
|
||||
@@ -205,7 +206,7 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
||||
cli = &subsonicMP.SubsonicServer{
|
||||
Client: subsonic.Client{
|
||||
UserAgent: ua,
|
||||
Client: &http.Client{Timeout: 10 * time.Second},
|
||||
Client: &http.Client{Timeout: timeout},
|
||||
BaseUrl: connection.Hostname,
|
||||
User: connection.Username,
|
||||
PasswordAuth: connection.LegacyAuth,
|
||||
@@ -216,7 +217,7 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
||||
altCli = &subsonicMP.SubsonicServer{
|
||||
Client: subsonic.Client{
|
||||
UserAgent: ua,
|
||||
Client: &http.Client{Timeout: 10 * time.Second},
|
||||
Client: &http.Client{Timeout: timeout},
|
||||
BaseUrl: connection.AltHostname,
|
||||
User: connection.Username,
|
||||
PasswordAuth: connection.LegacyAuth,
|
||||
|
||||
@@ -691,9 +691,10 @@ func (c *Controller) trySetPasswordAndConnectToServer(server *backend.ServerConf
|
||||
return c.tryConnectToServer(context.Background(), server, password)
|
||||
}
|
||||
|
||||
// try to connect to the given server, with a 10 second timeout added to the context
|
||||
// try to connect to the given server, with the configured timeout added to the context
|
||||
func (c *Controller) tryConnectToServer(ctx context.Context, server *backend.ServerConfig, password string) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
timeout := time.Duration(c.App.Config.Application.RequestTimeoutSeconds) * time.Second
|
||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||
defer cancel()
|
||||
if err := c.App.ServerManager.TestConnectionAndAuth(ctx, server.ServerConnection, password); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user