Skip to content

Commit 022212d

Browse files
committed
fix WS reconnection
1 parent b0bc2a0 commit 022212d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/service/depth.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (s *DepthSrv) Start() {
5656
}
5757

5858
log.Debugf("%s %s depth websocket connected.", s.si.Class, s.si.Symbol)
59+
// Reset the reconnect backoff now that we have a successful connection
60+
d.Reset()
5961
select {
6062
case <-s.ctx.Done():
6163
stopC <- struct{}{}
@@ -126,9 +128,14 @@ func (s *DepthSrv) wsHandler(event *spot.WsPartialDepthEvent) {
126128
}
127129

128130
func (s *DepthSrv) errHandler(err error) {
129-
if strings.Contains(err.Error(), "context canceled") {
131+
msg := err.Error()
132+
switch {
133+
case strings.Contains(msg, "context canceled"):
130134
log.Warnf("%s %s depth websocket context canceled, will restart connection.", s.si.Class, s.si.Symbol)
131-
} else {
135+
case strings.Contains(msg, "use of closed network connection"):
136+
// This commonly indicates a normal remote close/rotation; treat as info/debug to reduce noise
137+
log.Infof("%s %s depth websocket closed by peer; reconnecting.", s.si.Class, s.si.Symbol)
138+
default:
132139
log.Errorf("%s %s depth websocket connection error: %s.", s.si.Class, s.si.Symbol, err)
133140
}
134141
}

0 commit comments

Comments
 (0)