Skip to content

Commit 6574c17

Browse files
authored
make HTTP retry when the GoPro is overwhelmed (#128)
* switch to retryablehttp to allow downloading many files My HERO12 did not like being asked for more than about 5-7 files simultaneously, but dropped some of the /gp/gpMediaMetadata with a timeout. So after the files where the call to gpMediaMetadata was successfull were downloaded, I got presented with a bunch of errors where it didn't work, and of cause the files were not downloaded. Switching to a retrying approach means that we still hammer the GoPro for the first couple seconds, but allow the requests to proceed later. Some of this is still WIP - the config file has a timeout option, that I dropped since I do not understand enough go to incorporate it, yet. * use the configurable timeout sensibly
1 parent 95223b0 commit 6574c17

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ require (
4242
github.com/google/go-querystring v1.0.0 // indirect
4343
github.com/google/uuid v1.1.2 // indirect
4444
github.com/gookit/color v1.2.9 // indirect
45+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
46+
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
4547
github.com/hashicorp/hcl v1.0.0 // indirect
4648
github.com/inconshreveable/mousetrap v1.0.0 // indirect
4749
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,12 @@ github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN
245245
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
246246
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
247247
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
248+
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
249+
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
248250
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
249251
github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
250252
github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
253+
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
251254
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
252255
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
253256
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
@@ -257,6 +260,8 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh
257260
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
258261
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
259262
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
263+
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
264+
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
260265
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
261266
github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
262267
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=

pkg/utils/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"net/http"
55
"time"
66

7+
"github.com/hashicorp/go-retryablehttp"
78
"github.com/spf13/viper"
89
)
910

@@ -13,6 +14,14 @@ func timeoutFromConfig() int {
1314
return viper.GetInt(key)
1415
}
1516

16-
var Client = &http.Client{
17-
Timeout: time.Duration(timeoutFromConfig()) * time.Second,
17+
var Client *http.Client
18+
19+
func init() {
20+
retryableClient := retryablehttp.NewClient()
21+
retryableClient.Logger = nil
22+
retryableClient.Backoff = retryablehttp.LinearJitterBackoff
23+
timeout := time.Duration(timeoutFromConfig()) * time.Second
24+
retryableClient.RetryWaitMin = timeout / 10
25+
retryableClient.RetryWaitMax = timeout
26+
Client = retryableClient.StandardClient()
1827
}

0 commit comments

Comments
 (0)