Skip to content

Commit

Permalink
detect network errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Payeur Levallois committed Apr 11, 2017
1 parent 38ede3b commit 4672d31
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"math/rand"
"net"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -86,8 +87,14 @@ func (h *HTTPSender) RRSend(body []byte) error {
for {
bodyReader := bytes.NewReader(body)
if err := h.send(bodyReader); err != nil {
log.Printf("Backing off sending: %s", err)
return nil
// Network error
if uerr, ok := err.(*url.Error); ok {
if nerr, ok := uerr.Err.(*net.OpError); ok {
log.Printf("Network error, backing off sending: %s", nerr)
time.Sleep(time.Second)
continue
}
}

//Round robin
h.currentHost = (h.currentHost + 1) % len(h.hosts)
Expand Down

0 comments on commit 4672d31

Please sign in to comment.