From 32aeb37d1029a7c1e67f2adb87082b3b68d76cc8 Mon Sep 17 00:00:00 2001 From: stormcat24 Date: Fri, 7 Jul 2017 11:54:44 +0900 Subject: [PATCH] fixed panic to send closed channel --- manager/client.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/manager/client.go b/manager/client.go index 991623c..c4f1ff9 100644 --- a/manager/client.go +++ b/manager/client.go @@ -110,7 +110,7 @@ func (cm *ClientManager) SendPayload(payload event.Payload) { wg2.Add(1) go func(client chan event.Payload) { defer wg2.Done() - client <- payload + sendPayloadSafety(client, payload) }(client) } wg2.Wait() @@ -119,6 +119,16 @@ func (cm *ClientManager) SendPayload(payload event.Payload) { wg.Wait() } +func sendPayloadSafety(client chan event.Payload, payload event.Payload) { + defer func() { + if err := recover(); err != nil { + return + } + }() + client <- payload + return +} + const heartBeatEvent = "heartbeat" func (cm *ClientManager) SendHeartBeat() {