From aa2a2d4668c8b74999532daa3803497234537857 Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Tue, 19 Oct 2021 18:19:58 +0800 Subject: [PATCH] aa --- business/jxstore/event/event_tcp.go | 4 +++- business/jxstore/event/event_tcp_utils.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index f83eb5743..492332e5c 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -180,7 +180,9 @@ func (t *TcpClient) HandleTcpMessages(printNo string) { printMsg.Status = printMsgAlreadyLoad //先避免重复读再插到channel? if _, err := dao.UpdateEntity(db, printMsg, "Status"); err == nil { - t.addMsgChan(printMsg) + if err = t.addMsgChan(printMsg); err != nil { + globals.SugarLogger.Debugf("HandleTcpMessages addMsgChan Err: %v", err) + } } } } diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index af6a8f713..c0355e982 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -259,15 +259,21 @@ func (t *TcpClient) setPrintStatusTime(key string) { } } -func (t *TcpClient) addMsgChan(printMsg *model.PrintMsg) { +func (t *TcpClient) addMsgChan(printMsg *model.PrintMsg) (err error) { t.Lock() - defer t.Unlock() + defer func() { + t.Unlock() + if r := recover(); r != nil && r.(error).Error() == "send on closed channel" { + err = fmt.Errorf("send on closed channel") + } + }() if t.MsgMap[printMsg.PrintNo] == nil { dataChan := make(chan *model.PrintMsg, 1024) t.MsgMap[printMsg.PrintNo] = dataChan } globals.SugarLogger.Debugf("addMsgChan msgID: %s", printMsg.MsgID) t.MsgMap[printMsg.PrintNo] <- printMsg + return err } func (t *TcpClient) addCallbackChan(key, data string) {