Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: close of closed channel #7

Open
visoeclipse opened this issue Nov 3, 2016 · 3 comments
Open

panic: close of closed channel #7

visoeclipse opened this issue Nov 3, 2016 · 3 comments

Comments

@visoeclipse
Copy link

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
Copy link

nguyenthenguyen commented Jan 14, 2017

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants