Skip to content

Commit

Permalink
Don't log errors when context is cancelled
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Apr 3, 2023
1 parent 63e25ee commit 2449868
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package remotedialer

import (
"context"
"errors"
"io/ioutil"
"net/http"
"time"
Expand All @@ -17,8 +18,10 @@ type ConnectAuthorizer func(proto, address string) bool
func ClientConnect(ctx context.Context, wsURL string, headers http.Header, dialer *websocket.Dialer,
auth ConnectAuthorizer, onConnect func(context.Context, *Session) error) error {
if err := ConnectToProxy(ctx, wsURL, headers, auth, dialer, onConnect); err != nil {
logrus.WithError(err).Error("Remotedialer proxy error")
time.Sleep(time.Duration(5) * time.Second)
if !errors.Is(err, context.Canceled) {
logrus.WithError(err).Error("Remotedialer proxy error")
time.Sleep(time.Duration(5) * time.Second)
}
return err
}
return nil
Expand All @@ -34,7 +37,9 @@ func ConnectToProxy(rootCtx context.Context, proxyURL string, headers http.Heade
ws, resp, err := dialer.DialContext(rootCtx, proxyURL, headers)
if err != nil {
if resp == nil {
logrus.WithError(err).Errorf("Failed to connect to proxy. Empty dialer response")
if !errors.Is(err, context.Canceled) {
logrus.WithError(err).Errorf("Failed to connect to proxy. Empty dialer response")
}
} else {
rb, err2 := ioutil.ReadAll(resp.Body)
if err2 != nil {
Expand Down

0 comments on commit 2449868

Please sign in to comment.