From 14c25a6be6d147f90011d0218380bf7cd58b76e5 Mon Sep 17 00:00:00 2001
From: gongshangguo <gongshangguo@admin.com>
Date: 星期二, 01 三月 2022 20:05:27 +0800
Subject: [PATCH] 关闭的通道禁止写入

---
 client/client.go |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/client/client.go b/client/client.go
index 96bfe94..532803b 100644
--- a/client/client.go
+++ b/client/client.go
@@ -6,6 +6,7 @@
 	"bufio"
 	"encoding/binary"
 	"encoding/json"
+	"errors"
 	uuid "github.com/satori/go.uuid"
 	"go.uber.org/zap"
 	"io"
@@ -239,6 +240,12 @@
 			c.Logger.Error("Write Body Error:", err)
 		}
 	}()
+
+	if c.IsClosed() {
+		errMsg := "Can not write msg into closed chain"
+		c.Logger.Warn(errMsg, zap.Any("msg",body))
+		return errors.New(errMsg)
+	}
 	body.Receiver = aiot.RECEIVER_TO_SAAS
 	msgData, err := json.Marshal(body)
 	if err != nil {

--
Gitblit v1.8.0