mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
修复添加服务器死锁
This commit is contained in:
parent
71efbdfbe9
commit
41c4e2c1a0
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user