Skip to content

Commit

Permalink
Do not update to disconnected if initial connect fails due to invalid…
Browse files Browse the repository at this point in the history
… cert
  • Loading branch information
martonp committed May 14, 2022
1 parent 11a5197 commit 2053473
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion client/comms/wsconn.go
Expand Up @@ -189,6 +189,21 @@ func (conn *wsConn) setConnectionStatus(status ConnectionStatus) {
}
}

// setStatusToDisconnectedIfConnected will update the conenction status
// to disconnected if it was previously connected, but it will not overwrite
// another more specific disconnected status, such as InvalidCert.
func (conn *wsConn) setStatusToDisconnectedIfConnected() {
conn.connectedMtx.Lock()
statusChange := conn.connectionStatus == Connected
if statusChange {
conn.connectionStatus = Disconnected
}
conn.connectedMtx.Unlock()
if statusChange && conn.cfg.ConnectEventFunc != nil {
conn.cfg.ConnectEventFunc(Disconnected)
}
}

// connect attempts to establish a websocket connection.
func (conn *wsConn) connect(ctx context.Context) error {
dialer := &websocket.Dialer{
Expand Down Expand Up @@ -427,7 +442,7 @@ func (conn *wsConn) Connect(ctx context.Context) (*sync.WaitGroup, error) {
go func() {
defer conn.wg.Done()
<-ctxInternal.Done()
conn.setConnectionStatus(Disconnected)
conn.setStatusToDisconnectedIfConnected()
conn.wsMtx.Lock()
if conn.ws != nil {
conn.log.Debug("Sending close 1000 (normal) message.")
Expand Down

0 comments on commit 2053473

Please sign in to comment.