From 6a0fc08c327fbeb6a9d160adb5131aec666b0050 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Wed, 14 Aug 2019 13:15:11 -0400 Subject: [PATCH] better retry effort to cope with timeouts --- activity.go | 38 ++++++++++++++++++++++---------------- docs/changelog.txt | 2 ++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/activity.go b/activity.go index fa0e19b..90bc680 100644 --- a/activity.go +++ b/activity.go @@ -86,13 +86,31 @@ func PostMsg(keyname string, key *rsa.PrivateKey, url string, msg []byte) error } func GetJunk(url string) (junk.Junk, error) { - return GetJunkTimeout(url, 0) + return GetJunkTimeout(url, 30*time.Second) } func GetJunkFast(url string) (junk.Junk, error) { return GetJunkTimeout(url, 5*time.Second) } +func GetJunkHardMode(url string) (junk.Junk, error) { + j, err := GetJunk(url) + if err != nil { + emsg := err.Error() + if emsg == "http get status: 502" || strings.Contains(emsg, "timeout") { + log.Printf("trying again after error: %s", emsg) + time.Sleep(time.Duration(60+notrand.Int63n(60)) * time.Second) + j, err = GetJunk(url) + if err != nil { + log.Printf("still couldn't get it") + } else { + log.Printf("retry success!") + } + } + } + return j, err +} + func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) { at := thefakename if strings.Contains(url, ".well-known/webfinger?resource") { @@ -437,7 +455,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { log.Printf("in too deep") return } - obj, err := GetJunk(xid) + obj, err := GetJunkHardMode(xid) if err != nil { log.Printf("error getting oneup: %s", err) return @@ -472,19 +490,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { return nil } log.Printf("getting bonk: %s", xid) - obj, err = GetJunk(xid) - if err != nil { - log.Printf("error regetting: %s", err) - if err.Error() == "http get status: 502" { - time.Sleep(time.Duration(60+notrand.Int63n(60)) * time.Second) - obj, err = GetJunk(xid) - if err != nil { - log.Printf("still couldn't get it") - } else { - log.Printf("retry success!") - } - } - } + obj, err = GetJunkHardMode(xid) origin = originate(xid) what = "bonk" case "Create": @@ -492,7 +498,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { if !ok { xid, _ = obj.GetString("object") log.Printf("getting created honk: %s", xid) - obj, err = GetJunk(xid) + obj, err = GetJunkHardMode(xid) if err != nil { log.Printf("error getting creation: %s", err) } diff --git a/docs/changelog.txt b/docs/changelog.txt index a6d100a..75a50e3 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ More robust retries for fetching objects. + + Don't decode excessively large images and run out of memory. -- 0.7.7