Skip to content

Commit

Permalink
Add another sleep to the canary reconnects this time if connection su…
Browse files Browse the repository at this point in the history
…cceeds but there is an error receiving the stream. (#1581)

Signed-off-by: Edward Welch <edward.welch@grafana.com>
  • Loading branch information
slim-bean authored and cyriltovena committed Jan 24, 2020
1 parent 62cdc4a commit 790ba40
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/canary/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ func (r *Reader) run() {
close(r.done)
return
}
fmt.Fprintf(r.w, "error reading websocket: %s\n", err)
fmt.Fprintf(r.w, "error reading websocket, will retry in 10 seconds: %s\n", err)
// Even though we sleep between connection retries, we found it's possible to DOS Loki if the connection
// succeeds but some other error is returned, so also sleep here before retrying.
<-time.After(10 * time.Second)
r.closeAndReconnect()
continue
}
Expand Down Expand Up @@ -207,7 +210,7 @@ func (r *Reader) closeAndReconnect() {
c, _, err := websocket.DefaultDialer.Dial(u.String(), r.header)
if err != nil {
fmt.Fprintf(r.w, "failed to connect to %s with err %s\n", u.String(), err)
<-time.After(5 * time.Second)
<-time.After(10 * time.Second)
continue
}
r.conn = c
Expand Down

0 comments on commit 790ba40

Please sign in to comment.