Skip to content

Commit 546c47a

Browse files
author
Al S-M
committed
Reorder steps in disconnect and close the router stop channel.
Also add net/http/pprof to test cases for debugging.
1 parent 28e323f commit 546c47a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

client.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,14 @@ func (c *Client) internalConnLost(err error) {
384384

385385
func (c *Client) disconnect() {
386386
select {
387-
case _, ok := <-c.stop:
388-
if ok {
389-
close(c.stop)
390-
}
387+
case <-c.stop:
388+
//someone else has already closed the channel, must be error
389+
default:
390+
close(c.stop)
391391
}
392-
//Wait for all workers to finish before closing connection
393-
c.workers.Wait()
394392
c.conn.Close()
393+
c.workers.Wait()
394+
close(c.stopRouter)
395395
DEBUG.Println(CLI, "disconnected")
396396
c.persist.Close()
397397
}

unit_client_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ package mqtt
1616

1717
import (
1818
"log"
19+
"net/http"
1920
"os"
2021
"testing"
22+
23+
_ "net/http/pprof"
2124
)
2225

2326
func init() {
2427
DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime)
2528
WARN = log.New(os.Stderr, "WARNING ", log.Ltime)
2629
CRITICAL = log.New(os.Stderr, "CRITICAL ", log.Ltime)
30+
ERROR = log.New(os.Stderr, "ERROR ", log.Ltime)
31+
32+
go func() {
33+
log.Println(http.ListenAndServe("localhost:6060", nil))
34+
}()
2735
}
2836

2937
func Test_NewClient_simple(t *testing.T) {

0 commit comments

Comments
 (0)