Fix metadata timeouts

This commit is contained in:
Přemysl Eric Janouch 2018-11-03 00:54:50 +01:00
parent 23683424a6
commit 783fce1175
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 9 additions and 8 deletions

17
main.go
View File

@ -122,21 +122,22 @@ func resolveM3U8(target string) (out []string, err error) {
func metaProc(ctx context.Context, name string, out chan<- string) { func metaProc(ctx context.Context, name string, out chan<- string) {
defer close(out) defer close(out)
// "polling_timeout" seems to normally be 25 seconds, which is a lot,
// especially considering all the possible additional buffering.
const maxInterval = 5 * time.Second
var current, last string var current, last string
var interval time.Duration var interval time.Duration
for { for {
meta, err := getMeta(name) meta, err := getMeta(name)
if err != nil { if err != nil {
current = name + " - " + err.Error() current = name + " - " + err.Error()
interval = 30 * time.Second interval = maxInterval
} else { } else {
current = meta.title current = meta.title
interval = time.Duration(meta.timeout) interval = time.Duration(meta.timeout) * time.Millisecond
if interval > maxInterval {
// It seems to normally use 25 seconds which is a lot, interval = maxInterval
// especially considering all the possible additional buffering.
if interval > 5000 {
interval = 5000
} }
} }
if current != last { if current != last {
@ -149,7 +150,7 @@ func metaProc(ctx context.Context, name string, out chan<- string) {
} }
select { select {
case <-time.After(time.Duration(interval) * time.Millisecond): case <-time.After(interval):
case <-ctx.Done(): case <-ctx.Done():
return return
} }