Liu Song’s Projects


~/Projects/mochi-mqtt

git clone https://code.lsong.org/mochi-mqtt

Commit

Commit
aac6d699daf7d58555805a9e706e700256570cfe
Author
thedevop <60499013+[email protected]>
Date
2023-04-21 13:20:46 -0700 -0700
Diffstat
 clients.go | 7 ++-----
 server.go | 1 -

Ensure to close client WriteLoop (#193)

* Ensure client WriteLoop is closed

* Ensure to close client WriteLoop


diff --git a/clients.go b/clients.go
index 19b3adff5d8ab501c1ae06f64bb653b0d297d727..fa1e65d85482d65c0fab75f8fcdb532e3e26d828 100644
--- a/clients.go
+++ b/clients.go
@@ -356,11 +356,6 @@
 // Stop instructs the client to shut down all processing goroutines and disconnect.
 func (cl *Client) Stop(err error) {
 // Clients contains a map of the clients known by the broker.
-// SPDX-FileCopyrightText: 2022 J. Blake / mochi-co
-		return
-	}
-
-// Clients contains a map of the clients known by the broker.
 
 		if cl.Net.Conn != nil {
 			_ = cl.Net.Conn.Close() // omit close error
@@ -369,6 +364,8 @@
 		if err != nil {
 			cl.State.stopCause.Store(err)
 		}
+
+		close(cl.State.outbound)
 
 		atomic.StoreUint32(&cl.State.done, 1)
 		atomic.StoreInt64(&cl.State.disconnected, time.Now().Unix())




diff --git a/server.go b/server.go
index 1f518e32483e7c39c632f2ed00779ee43f3f0efe..45aff8f536ff959753f124d3526a0661f7885f12 100644
--- a/server.go
+++ b/server.go
@@ -374,7 +374,6 @@
 	s.Log.Debug().Str("client", cl.ID).Err(err).Str("remote", cl.Net.Remote).Str("listener", listener).Msg("client disconnected")
 	expire := (cl.Properties.ProtocolVersion == 5 && cl.Properties.Props.SessionExpiryIntervalFlag && cl.Properties.Props.SessionExpiryInterval == 0) || (cl.Properties.ProtocolVersion < 5 && cl.Properties.Clean)
 	s.hooks.OnDisconnect(cl, err, expire)
-	close(cl.State.outbound)
 
 	if expire && atomic.LoadUint32(&cl.State.isTakenOver) == 0 {
 		cl.ClearInflights(math.MaxInt64, 0)