Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sleep to canary reconnect on error #1581

Merged
merged 1 commit into from
Jan 24, 2020
Merged

Add sleep to canary reconnect on error #1581

merged 1 commit into from
Jan 24, 2020

Conversation

slim-bean
Copy link
Collaborator

We previously limited retries on websocket connections when the connection failed, however if the connection succeded but another error was returned we would close and reopen the websocket immediately.

This kills the Loki

Signed-off-by: Edward Welch edward.welch@grafana.com

…cceeds but there is an error receiving the stream.

Signed-off-by: Edward Welch <edward.welch@grafana.com>
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not time.Sleep here?

Copy link
Contributor

@mattmendick mattmendick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks just wonderful to me

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you did above, perhaps you want to add how many seconds it will sleep for in the log message?

@cyriltovena cyriltovena merged commit 790ba40 into master Jan 24, 2020
@cyriltovena cyriltovena deleted the canary-dos branch January 24, 2020 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants