Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/wsclient/wsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,13 @@ func buildWSUrl(ctx context.Context, config *WSConfig) (string, error) {

func (w *wsClient) connect(initial bool) error {
l := log.L(w.ctx)
l.Debugf("WS %s connecting, isInitial: %t", w.url, initial)
return w.connRetry.DoCustomLog(w.ctx, func(attempt int) (retry bool, err error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

aah DoCustomLog doesn't log attempts, now it makes sense to add the below attempt logs!

if w.closed {
l.Errorf("WS %s is closed, no retry will be attempted", w.url)
return false, i18n.NewError(w.ctx, i18n.MsgWSClosing)
}

l.Debugf("WS %s connect attempt %d", w.url, attempt)
retry = w.backgroundConnect || !initial || attempt < w.initialRetryAttempts
if w.beforeConnect != nil {
if err = w.beforeConnect(w.ctx, w); err != nil {
Expand All @@ -393,7 +395,7 @@ func (w *wsClient) connect(initial bool) error {
l.Warnf("WS %s connect attempt %d failed [%d]: %s", w.url, attempt, status, errMsg)
return retry, i18n.WrapError(w.ctx, err, i18n.MsgWSConnectFailed)
}

l.Debugf("WS %s connect attempt %d succeeded", w.url, attempt)
w.pongReceivedOrReset(false)
w.wsconn.SetPongHandler(w.pongHandler)
l.Infof("WS %s connected", w.url)
Expand Down Expand Up @@ -544,6 +546,7 @@ func (w *wsClient) receiveReconnectLoop() {
var err error
if w.afterConnect != nil {
err = w.afterConnect(w.ctx, w)
l.Debugf("WS %s afterConnect (error: %s)", w.url, err)
Comment thread
Chengxuan marked this conversation as resolved.
Outdated
Comment thread
Chengxuan marked this conversation as resolved.
Outdated
}

if err == nil {
Expand All @@ -559,21 +562,23 @@ func (w *wsClient) receiveReconnectLoop() {
// Ensure the connection is closed after the sender and receivers exit
err = w.wsconn.Close()
if err != nil {
l.Debugf("WS %s close failed: %s", w.url, err)
l.Warnf("WS %s ignoring websocket connection close error: %s", w.url, err)
Comment thread
Chengxuan marked this conversation as resolved.
Outdated
Comment thread
Chengxuan marked this conversation as resolved.
Outdated
}
l.Debugf("WS %s reset the connection", w.url)
w.sendDone = nil
w.wsconn = nil
}

if w.disableReconnect {
l.Infof("WS %s exiting (disableReconnect)", w.url)
return
}

// Go into reconnect
if !w.closed {
err = w.connect(false)
if err != nil {
l.Debugf("WS %s exiting: %s", w.url, err)
l.Errorf("WS %s exiting due to connect error: %s", w.url, err)
Comment thread
Chengxuan marked this conversation as resolved.
Outdated
Comment thread
Chengxuan marked this conversation as resolved.
Outdated
return
}
}
Expand Down