mirror of
https://github.com/fhmq/hmq.git
synced 2026-05-04 07:08:32 +00:00
fix: 🐛 fixes race condition (#155)
- this race condition occurs when a client is disconnected or when hmq checks if client still alive Signed-off-by: Lucas Vieira <lucas.engen.cc@gmail.com>
This commit is contained in:
@@ -808,9 +808,10 @@ func (c *client) Close() {
|
||||
Timestamp: time.Now().Unix(),
|
||||
})
|
||||
|
||||
if c.conn != nil {
|
||||
if c.mu.Lock(); c.conn != nil {
|
||||
_ = c.conn.Close()
|
||||
c.conn = nil
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
if b == nil {
|
||||
|
||||
@@ -195,8 +195,10 @@ func (c *client) retryDelivery() {
|
||||
c.resetRetryTimer()
|
||||
c.inflightMu.RLock()
|
||||
ilen := len(c.inflight)
|
||||
if c.conn == nil || ilen == 0 { //Reset timer when client offline OR inflight is empty
|
||||
|
||||
if c.mu.Lock(); c.conn == nil || ilen == 0 { //Reset timer when client offline OR inflight is empty
|
||||
c.inflightMu.RUnlock()
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user