Skip to content

Commit

Permalink
fix(fc2): add more context timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkness4 committed Sep 22, 2023
1 parent 5e14a8e commit 44bca1c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions fc2/fc2_livestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ func (ls *LiveStream) WaitForOnline(ctx context.Context, interval time.Duration)
}

func (ls *LiveStream) IsOnline(ctx context.Context, options ...GetMetaOptions) (bool, error) {
ls.log.Debug().Msg("checking if online")

return try.DoExponentialBackoffWithContextAndResult(
ctx,
5,
Expand Down Expand Up @@ -97,14 +95,14 @@ func (ls *LiveStream) GetMeta(
ctx context.Context,
options ...GetMetaOptions,
) (*GetMetaData, error) {
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
if len(options) > 0 {
if !options[0].Refetch && ls.meta != nil {
return ls.meta, nil
}
}

ls.log.Debug().Msg("fetching new meta")

v := url.Values{
"channel": []string{"1"},
"profile": []string{"1"},
Expand Down Expand Up @@ -196,6 +194,8 @@ func (ls *LiveStream) GetWebSocketURL(ctx context.Context) (string, error) {
"client_app": []string{"browser_hls"},
"ipv6": []string{""},
}
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(
ctx,
"POST",
Expand Down
2 changes: 2 additions & 0 deletions fc2/fc2_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func (w *WebSocket) sendMessage(
arguments interface{},
msgID int,
) error {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
// Build message
msgObj := make(map[string]interface{})
msgObj["name"] = name
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ require (
github.com/kisielk/errcheck v1.6.3 // indirect
github.com/kisielk/gotool v1.0.0 // indirect
github.com/kkHAIKE/contextcheck v1.1.4 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/kulti/thelper v0.6.3 // indirect
github.com/kunwardeep/paralleltest v1.0.8 // indirect
github.com/kyoh86/exportloopref v0.1.11 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ github.com/kkHAIKE/contextcheck v1.1.4/go.mod h1:1+i/gWqokIa+dm31mqGLZhZJ7Uh44DJ
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
Expand Down
4 changes: 4 additions & 0 deletions hls/hls_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func NewDownloader(
}

func (hls *Downloader) GetFragmentURLs(ctx context.Context) ([]string, error) {
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", hls.url, nil)
if err != nil {
return []string{}, err
Expand Down Expand Up @@ -141,6 +143,8 @@ func (hls *Downloader) fillQueue(ctx context.Context, urlChan chan<- string) err
}

func (hls *Downloader) download(ctx context.Context, url string) ([]byte, error) {
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return []byte{}, err
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ var app = &cli.App{
HasBeenSet: true,
Action: func(ctx *cli.Context, s bool) error {
if s {
log.Logger = log.Logger.Level(zerolog.DebugLevel)
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
log.Logger = log.Logger.Level(zerolog.InfoLevel)
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
return nil
Expand Down

0 comments on commit 44bca1c

Please sign in to comment.