修复添加服务器死锁

This commit is contained in:
奶爸 2019-12-11 14:41:12 +08:00
parent 71efbdfbe9
commit 41c4e2c1a0
2 changed files with 3 additions and 3 deletions

View File

@ -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,

View File

@ -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