Skip to content

Commit

Permalink
fix(conn): conn status nil exception
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyong Huang <huangjy@emqx.io>
  • Loading branch information
ngjaying committed Nov 11, 2024
1 parent 29a9eb2 commit fde4cfc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/connection/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,19 @@ func (meta *Meta) GetStatus() (s string, e string) {
if ss != nil {
s = ss.(string)
if s == api.ConnectionConnected {
e = ""
// if connected, cw, cw.conn should exist
if _, isStateful := meta.cw.conn.(modules.StatefulDialer); !isStateful {
err := meta.cw.conn.Ping(context.Background())
if err != nil {
s = api.ConnectionDisconnected
e = err.Error()
if meta.cw.IsInitialized() {
conn, err := meta.cw.Wait(context.Background())
if err != nil || conn == nil {
return
}
e = ""
// if connected, cw, cw.conn should exist
if _, isStateful := conn.(modules.StatefulDialer); !isStateful {
err := conn.Ping(context.Background())
if err != nil {
s = api.ConnectionDisconnected
e = err.Error()
}
}
}
}
Expand Down

0 comments on commit fde4cfc

Please sign in to comment.