From 41c4e2c1a0a12f728545357d2aac8e27961b8c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=B6=E7=88=B8?= Date: Wed, 11 Dec 2019 14:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E6=AD=BB=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/dashboard/controller/member_api.go | 4 ++-- service/rpc/nezha.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index 9cc2667..93f8bac 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -40,6 +40,8 @@ func (ma *memberAPI) addServer(c *gin.Context) { var s model.Server err := c.ShouldBindJSON(&sf) if err == nil { + dao.ServerLock.Lock() + defer dao.ServerLock.Unlock() s.Name = sf.Name s.Secret = com.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, dao.Admin.ID)) s.Secret = s.Secret[:10] @@ -52,8 +54,6 @@ func (ma *memberAPI) addServer(c *gin.Context) { }) return } - dao.ServerLock.Lock() - defer dao.ServerLock.Unlock() dao.ServerList[fmt.Sprintf("%d", s.ID)] = &s c.JSON(http.StatusOK, model.Response{ Code: http.StatusOK, diff --git a/service/rpc/nezha.go b/service/rpc/nezha.go index a8eca69..dcc118c 100644 --- a/service/rpc/nezha.go +++ b/service/rpc/nezha.go @@ -36,10 +36,10 @@ func (s *NezhaHandler) Heartbeat(r *pb.Beat, stream pb.NezhaService_HeartbeatSer return err } dao.ServerLock.RLock() - defer dao.ServerLock.RUnlock() closeCh := make(chan error) dao.ServerList[clientID].StreamClose = closeCh dao.ServerList[clientID].Stream = stream + dao.ServerLock.RUnlock() select { case err = <-closeCh: return err