mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 20:58: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
|
var s model.Server
|
||||||
err := c.ShouldBindJSON(&sf)
|
err := c.ShouldBindJSON(&sf)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
dao.ServerLock.Lock()
|
||||||
|
defer dao.ServerLock.Unlock()
|
||||||
s.Name = sf.Name
|
s.Name = sf.Name
|
||||||
s.Secret = com.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, dao.Admin.ID))
|
s.Secret = com.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, dao.Admin.ID))
|
||||||
s.Secret = s.Secret[:10]
|
s.Secret = s.Secret[:10]
|
||||||
@ -52,8 +54,6 @@ func (ma *memberAPI) addServer(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dao.ServerLock.Lock()
|
|
||||||
defer dao.ServerLock.Unlock()
|
|
||||||
dao.ServerList[fmt.Sprintf("%d", s.ID)] = &s
|
dao.ServerList[fmt.Sprintf("%d", s.ID)] = &s
|
||||||
c.JSON(http.StatusOK, model.Response{
|
c.JSON(http.StatusOK, model.Response{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
|
@ -36,10 +36,10 @@ func (s *NezhaHandler) Heartbeat(r *pb.Beat, stream pb.NezhaService_HeartbeatSer
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dao.ServerLock.RLock()
|
dao.ServerLock.RLock()
|
||||||
defer dao.ServerLock.RUnlock()
|
|
||||||
closeCh := make(chan error)
|
closeCh := make(chan error)
|
||||||
dao.ServerList[clientID].StreamClose = closeCh
|
dao.ServerList[clientID].StreamClose = closeCh
|
||||||
dao.ServerList[clientID].Stream = stream
|
dao.ServerList[clientID].Stream = stream
|
||||||
|
dao.ServerLock.RUnlock()
|
||||||
select {
|
select {
|
||||||
case err = <-closeCh:
|
case err = <-closeCh:
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user