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)
|
_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
||||||
})
|
})
|
||||||
if a.Config.Application.EnableLrcLib {
|
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() {
|
a.PlaybackManager.OnPlaying(func() {
|
||||||
|
|||||||
+2
-1
@@ -54,8 +54,8 @@ type AppConfig struct {
|
|||||||
Language string
|
Language string
|
||||||
DisableDPIDetection bool
|
DisableDPIDetection bool
|
||||||
EnableAutoUpdateChecker bool
|
EnableAutoUpdateChecker bool
|
||||||
|
RequestTimeoutSeconds int
|
||||||
|
|
||||||
// Experimental - may be removed in future
|
|
||||||
FontNormalTTF string
|
FontNormalTTF string
|
||||||
FontBoldTTF string
|
FontBoldTTF string
|
||||||
UIScaleSize string
|
UIScaleSize string
|
||||||
@@ -191,6 +191,7 @@ func DefaultConfig(appVersionTag string) *Config {
|
|||||||
EnqueueBatchSize: 100,
|
EnqueueBatchSize: 100,
|
||||||
Language: "auto",
|
Language: "auto",
|
||||||
EnableAutoUpdateChecker: true,
|
EnableAutoUpdateChecker: true,
|
||||||
|
RequestTimeoutSeconds: 15,
|
||||||
},
|
},
|
||||||
AlbumPage: AlbumPageConfig{
|
AlbumPage: AlbumPageConfig{
|
||||||
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},
|
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},
|
||||||
|
|||||||
+4
-3
@@ -26,12 +26,13 @@ const lrclibCacheFolder = "lrclib"
|
|||||||
type LrcLibFetcher struct {
|
type LrcLibFetcher struct {
|
||||||
cachePath string
|
cachePath string
|
||||||
customLrcLibUrl 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)
|
cachePath := filepath.Join(baseCacheDir, lrclibCacheFolder)
|
||||||
configdir.MakePath(cachePath)
|
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) {
|
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) {
|
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()
|
defer cancel()
|
||||||
|
|
||||||
lrclibUrl := l.getLrclibUrl()
|
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) {
|
func (s *ServerManager) connect(connection ServerConnection, password string) (mediaprovider.Server, error) {
|
||||||
var cli, altCli mediaprovider.Server
|
var cli, altCli mediaprovider.Server
|
||||||
|
timeout := time.Second * time.Duration(s.config.Application.RequestTimeoutSeconds)
|
||||||
|
|
||||||
if connection.ServerType == ServerTypeJellyfin {
|
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 {
|
if err != nil {
|
||||||
log.Printf("error creating Jellyfin client: %s", err.Error())
|
log.Printf("error creating Jellyfin client: %s", err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -190,7 +191,7 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
|||||||
}
|
}
|
||||||
|
|
||||||
if connection.AltHostname != "" {
|
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 {
|
if err != nil {
|
||||||
log.Printf("error creating Jellyfin alternative client: %s", err.Error())
|
log.Printf("error creating Jellyfin alternative client: %s", err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -205,7 +206,7 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
|||||||
cli = &subsonicMP.SubsonicServer{
|
cli = &subsonicMP.SubsonicServer{
|
||||||
Client: subsonic.Client{
|
Client: subsonic.Client{
|
||||||
UserAgent: ua,
|
UserAgent: ua,
|
||||||
Client: &http.Client{Timeout: 10 * time.Second},
|
Client: &http.Client{Timeout: timeout},
|
||||||
BaseUrl: connection.Hostname,
|
BaseUrl: connection.Hostname,
|
||||||
User: connection.Username,
|
User: connection.Username,
|
||||||
PasswordAuth: connection.LegacyAuth,
|
PasswordAuth: connection.LegacyAuth,
|
||||||
@@ -216,7 +217,7 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
|||||||
altCli = &subsonicMP.SubsonicServer{
|
altCli = &subsonicMP.SubsonicServer{
|
||||||
Client: subsonic.Client{
|
Client: subsonic.Client{
|
||||||
UserAgent: ua,
|
UserAgent: ua,
|
||||||
Client: &http.Client{Timeout: 10 * time.Second},
|
Client: &http.Client{Timeout: timeout},
|
||||||
BaseUrl: connection.AltHostname,
|
BaseUrl: connection.AltHostname,
|
||||||
User: connection.Username,
|
User: connection.Username,
|
||||||
PasswordAuth: connection.LegacyAuth,
|
PasswordAuth: connection.LegacyAuth,
|
||||||
|
|||||||
@@ -691,9 +691,10 @@ func (c *Controller) trySetPasswordAndConnectToServer(server *backend.ServerConf
|
|||||||
return c.tryConnectToServer(context.Background(), server, password)
|
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 {
|
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()
|
defer cancel()
|
||||||
if err := c.App.ServerManager.TestConnectionAndAuth(ctx, server.ServerConnection, password); err != nil {
|
if err := c.App.ServerManager.TestConnectionAndAuth(ctx, server.ServerConnection, password); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user