From 5860f1fa7a92d52b690e194e197f1ac43404d48e Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Fri, 10 Jun 2022 22:59:45 +0800 Subject: [PATCH] add send msg timeout --- internal/msg_gateway/gate/ws_server.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 5e69aa06c..cc8e179ae 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -90,13 +90,14 @@ func (ws *WServer) readMsg(conn *UserConn) { } func (ws *WServer) SetWriteTimeout(conn *UserConn, timeout int) { + conn.w.Lock() + defer conn.w.Unlock() conn.SetWriteDeadline(time.Now().Add(time.Duration(timeout) * time.Second)) } func (ws *WServer) writeMsg(conn *UserConn, a int, msg []byte) error { conn.w.Lock() defer conn.w.Unlock() - ws.SetWriteTimeout(conn, 5) return conn.WriteMessage(a, msg) } @@ -164,6 +165,7 @@ func (ws *WServer) sendKickMsg(oldConn, newConn *UserConn) { log.NewError(mReply.OperationID, mReply.ReqIdentifier, mReply.ErrCode, mReply.ErrMsg, "Encode Msg error", oldConn.RemoteAddr().String(), newConn.RemoteAddr().String(), err.Error()) return } + ws.SetWriteTimeout(oldConn, 5) err = ws.writeMsg(oldConn, websocket.BinaryMessage, b.Bytes()) if err != nil { log.NewError(mReply.OperationID, mReply.ReqIdentifier, mReply.ErrCode, mReply.ErrMsg, "WS WriteMsg error", oldConn.RemoteAddr().String(), newConn.RemoteAddr().String(), err.Error())