From 5555e1c5c0f1c8faeac01a78aa3f427206c1d8a0 Mon Sep 17 00:00:00 2001 From: Markus Grüneis Date: Fri, 24 Oct 2014 19:47:57 +0200 Subject: hub: Retry on GET /lastupdate error instead of panic. --- src/hub/src/spreadspace.org/sfive/s5srvForward.go | 33 +++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/hub') diff --git a/src/hub/src/spreadspace.org/sfive/s5srvForward.go b/src/hub/src/spreadspace.org/sfive/s5srvForward.go index 4707dd5..b5ff45a 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srvForward.go +++ b/src/hub/src/spreadspace.org/sfive/s5srvForward.go @@ -20,33 +20,39 @@ func findMaxId(values []StatisticsData) int { return maxId } -func (self StatsSinkServer) getLastUpdate(baseurl string, client *http.Client) (latestId int, storeId string) { - storeId, err := self.store.GetStoreId() +func (self StatsSinkServer) getLastUpdate(baseurl string, client *http.Client) (latestId int, storeId string, err error) { + storeId, err = self.store.GetStoreId() if err != nil { - s5l.Panicf("fwd: failed to get own hubid: %v\n", err) + s5l.Printf("fwd: failed to get own hubid: %v\n", err) + return } resp, err := client.Get(baseurl + "/lastupdate/" + storeId) if err != nil { - s5l.Panicf("fwd: failed to query for lastupdate: %v\n", err) + s5l.Printf("fwd: failed to query for lastupdate: %v\n", err) + return } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - s5l.Panicf("fwd: server failed to fulfill query for lastupdate: %v\n", resp.StatusCode) + s5l.Printf("fwd: server failed to fulfill query for lastupdate: %v\n", resp.StatusCode) + return } body, err := ioutil.ReadAll(resp.Body) if err != nil { - s5l.Panicf("fwd: failed to read lastupdate response: %v\n", err) + s5l.Printf("fwd: failed to read lastupdate response: %v\n", err) + return } if len(body) == 0 { latestId = -1 } else { - tid, err := strconv.ParseInt(string(body), 10, 32) - if err != nil { - s5l.Panicf("fwd: invalid lastupdate response: %v\n", err) + tid, errl := strconv.ParseInt(string(body), 10, 32) + if errl != nil { + s5l.Printf("fwd: invalid lastupdate response: %v\n", err) + err = errl + return } latestId = int(tid) } @@ -58,7 +64,12 @@ func (self StatsSinkServer) handleForwarding(baseurl string, client *http.Client url := baseurl + "/updates" tryResync: for { - lastId, _ := self.getLastUpdate(baseurl, client) + lastId, _, err := self.getLastUpdate(baseurl, client) + + if err != nil { + time.Sleep(5 * time.Second) + continue tryResync + } nextBatch: for { @@ -90,7 +101,7 @@ tryResync: lastId = findMaxId(updates) s5tl.Printf("fwd: new lastid: %d", lastId) - time.Sleep(100 * time.Millisecond) + time.Sleep(2 * time.Second) } } } -- cgit v1.2.3