diff --git a/exchanges/stream/websocket.go b/exchanges/stream/websocket.go index 7d9c9e4e..1ff43ccc 100644 --- a/exchanges/stream/websocket.go +++ b/exchanges/stream/websocket.go @@ -391,16 +391,15 @@ func (w *Websocket) connectionMonitor() error { } select { case err := <-w.ReadMessageErrors: - if isDisconnectionError(err) { + if IsDisconnectionError(err) { w.setInit(false) log.Warnf(log.WebsocketMgr, "%v websocket has been disconnected. Reason: %v", w.exchangeName, err) w.setConnectedStatus(false) - } else { - // pass off non disconnect errors to datahandler to manage - w.DataHandler <- err } + + w.DataHandler <- err case <-timer.C: if !w.IsConnecting() && !w.IsConnected() { err := w.Connect() @@ -983,8 +982,8 @@ func (w *Websocket) CanUseAuthenticatedEndpoints() bool { return w.canUseAuthenticatedEndpoints } -// isDisconnectionError Determines if the error sent over chan ReadMessageErrors is a disconnection error -func isDisconnectionError(err error) bool { +// IsDisconnectionError Determines if the error sent over chan ReadMessageErrors is a disconnection error +func IsDisconnectionError(err error) bool { if websocket.IsUnexpectedCloseError(err) { return true } diff --git a/exchanges/stream/websocket_connection.go b/exchanges/stream/websocket_connection.go index 1601c7a1..1a983654 100644 --- a/exchanges/stream/websocket_connection.go +++ b/exchanges/stream/websocket_connection.go @@ -216,7 +216,7 @@ func (w *WebsocketConnection) IsConnected() bool { func (w *WebsocketConnection) ReadMessage() Response { mType, resp, err := w.Connection.ReadMessage() if err != nil { - if isDisconnectionError(err) { + if IsDisconnectionError(err) { if w.setConnectedStatus(false) { // NOTE: When w.setConnectedStatus() returns true the underlying // state was changed and this infers that the connection was diff --git a/exchanges/stream/websocket_test.go b/exchanges/stream/websocket_test.go index 5d851b61..a5651d0f 100644 --- a/exchanges/stream/websocket_test.go +++ b/exchanges/stream/websocket_test.go @@ -230,11 +230,11 @@ func TestTrafficMonitorTimeout(t *testing.T) { func TestIsDisconnectionError(t *testing.T) { t.Parallel() - isADisconnectionError := isDisconnectionError(errors.New("errorText")) + isADisconnectionError := IsDisconnectionError(errors.New("errorText")) if isADisconnectionError { t.Error("Its not") } - isADisconnectionError = isDisconnectionError(&websocket.CloseError{ + isADisconnectionError = IsDisconnectionError(&websocket.CloseError{ Code: 1006, Text: "errorText", }) @@ -242,14 +242,14 @@ func TestIsDisconnectionError(t *testing.T) { t.Error("It is") } - isADisconnectionError = isDisconnectionError(&net.OpError{ + isADisconnectionError = IsDisconnectionError(&net.OpError{ Err: errClosedConnection, }) if isADisconnectionError { t.Error("It's not") } - isADisconnectionError = isDisconnectionError(&net.OpError{ + isADisconnectionError = IsDisconnectionError(&net.OpError{ Err: errors.New("errText"), }) if !isADisconnectionError { @@ -321,8 +321,10 @@ func TestConnectionMessageErrors(t *testing.T) { outer: for { select { - case <-ws.ToRoutine: - t.Fatal("Error is a disconnection error") + case err := <-ws.ToRoutine: + if _, ok := err.(*websocket.CloseError); !ok { + t.Errorf("Error is not a disconnection error: %v", err) + } case <-timer.C: break outer }