takanorig / mqtt-bench

Benchmark tool for MQTT Broker
144 stars 67 forks source link

panic: close of closed channel #7

Open visoeclipse opened 7 years ago

visoeclipse commented 7 years ago

help! thx

2016-11-03 19:21:12.040714115 +0800 CST Start benchmark 2016-11-03 19:21:12.22926646 +0800 CST End benchmark panic: close of closed channel

goroutine 1977 [running]: panic(0x231b80, 0xc42015a700) /usr/local/go/src/runtime/panic.go:500 +0x1a1 git.eclipse.org/gitroot/paho/org%2eeclipse%2epaho%2emqtt%2egolang%2egit.(Client).disconnect(0xc4208f8000) /Users/seven/Workspace/golang/src/git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git/client.go:428 +0x96 git.eclipse.org/gitroot/paho/org%2eeclipse%2epaho%2emqtt%2egolang%2egit.(Client).Disconnect(0xc4208f8000, 0xa) /Users/seven/Workspace/golang/src/git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git/client.go:388 +0x27c main.Disconnect(0xc4208f8000) /Users/seven/Workspace/golang/src/charge_platform/mqtt_broker/mqtt_benchmark.go:372 +0x34 main.AsyncDisconnect.func1(0xc42018a3c0, 0xc420210000) /Users/seven/Workspace/golang/src/charge_platform/mqtt_broker/mqtt_benchmark.go:363 +0x54 created by main.AsyncDisconnect /Users/seven/Workspace/golang/src/charge_platform/mqtt_broker/mqtt_benchmark.go:364 +0xca panic: close of closed channel

goroutine 1982 [running]: panic(0x231b80, 0xc420c46210) /usr/local/go/src/runtime/panic.go:500 +0x1a1 git.eclipse.org/gitroot/paho/org%2eeclipse%2epaho%2emqtt%2egolang%2egit.(Client).disconnect(0xc4204f2900) /Users/seven/Workspace/golang/src/git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git/client.go:428 +0x96 git.eclipse.org/gitroot/paho/org%2eeclipse%2epaho%2emqtt%2egolang%2egit.(Client).Disconnect(0xc4204f2900, 0xa) /Users/seven/Workspace/golang/src/git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git/client.go:388 +0x27c main.Disconnect(0xc4204f2900) /Users/seven/Workspace/golang/src/charge_platform/mqtt_broker/mqtt_benchmark.go:372 +0x34 main.AsyncDisconnect.func1(0xc42018a3c0, 0xc420210000) /Users/seven/Workspace/golang/src/charge_platform/mqtt_broker/mqtt_benchmark.go:363 +0x54 created by main.AsyncDisconnect /Users/seven/Workspace/golang/src/charge_platform/mqtt_broker/mqtt_benchmark.go:364 +0xca

nguyenthenguyen commented 7 years ago

AsyncDisconnect function should be:

func AsyncDisconnect(clients []*MQTT.Client) {
    wg := new(sync.WaitGroup)

    for _, client := range clients {
        wg.Add(1)
        client := client
        go func(c *MQTT.Client) {
            defer wg.Done()
            Disconnect(c)
        }(client)
    }

    wg.Wait()
}

Pull request #10

zcxzcxczcx commented 6 years ago

If I could delete "client:=client"? By my testing,I found that could.

func AsyncDisconnect(clients []MQTT.Client) { wg := new(sync.WaitGroup) for _, client := range clients { wg.Add(1) go func(c MQTT.Client) { defer wg.Done() Disconnect(c) }(client) } wg.Wait() }

nguyenthenguyen commented 6 years ago

@zcxzcxczcx Yes. You can remove client:=client. I have updated my pull request