Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 7 additions & 5 deletions broker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,12 @@ func (c *client) Close() {
Timestamp: time.Now().Unix(),
})

if c.mu.Lock(); c.conn != nil {
c.mu.Lock()
if c.conn != nil {
_ = c.conn.Close()
c.conn = nil
c.mu.Unlock()
}
c.mu.Unlock()

if b == nil {
return
Expand Down Expand Up @@ -905,13 +906,14 @@ func (c *client) WriterPacket(packet packets.ControlPacket) error {
if packet == nil {
return nil
}

c.mu.Lock()
defer c.mu.Unlock()

if c.conn == nil {
c.Close()
return errors.New("connect lost ....")
}

c.mu.Lock()
defer c.mu.Unlock()
return packet.Write(c.conn)
}

Expand Down
4 changes: 3 additions & 1 deletion broker/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ func (c *client) retryDelivery() {
c.inflightMu.RLock()
ilen := len(c.inflight)

if c.mu.Lock(); c.conn == nil || ilen == 0 { //Reset timer when client offline OR inflight is empty
c.mu.Lock()
if c.conn == nil || ilen == 0 { //Reset timer when client offline OR inflight is empty
c.inflightMu.RUnlock()
c.mu.Unlock()
return
}
c.mu.Unlock()

// copy the to be retried elements out of the map to only hold the lock for a short time and use the new slice later to iterate
// through them
Expand Down