fix sync.once bug
必须使用引用,如果单纯值传递,once 也被复制了一份,导致单例不起作用。
This commit is contained in:
parent
8df7498c33
commit
ca58af2865
@ -14,10 +14,10 @@ import (
|
||||
|
||||
// listServices return all service informations
|
||||
func (gs *gocServer) listServices(c *gin.Context) {
|
||||
agents := make([]gocCoveredAgent, 0)
|
||||
agents := make([]*gocCoveredAgent, 0)
|
||||
|
||||
gs.rpcClients.Range(func(key, value interface{}) bool {
|
||||
agent, ok := value.(gocCoveredAgent)
|
||||
agent, ok := value.(*gocCoveredAgent)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
@ -40,7 +40,7 @@ func (gs *gocServer) getProfiles(c *gin.Context) {
|
||||
mergedProfiles := make([][]*cover.Profile, 0)
|
||||
|
||||
gs.rpcClients.Range(func(key, value interface{}) bool {
|
||||
agent, ok := value.(gocCoveredAgent)
|
||||
agent, ok := value.(*gocCoveredAgent)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
@ -80,7 +80,6 @@ func (gs *gocServer) getProfiles(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// append profile
|
||||
profile, err := convertProfile([]byte(res))
|
||||
if err != nil {
|
||||
|
@ -41,7 +41,7 @@ func (gs *gocServer) serveRpcStream(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
gocA := gocCoveredAgent{
|
||||
gocA := &gocCoveredAgent{
|
||||
RemoteIP: remoteIP.String(),
|
||||
Hostname: hostname,
|
||||
Pid: pid,
|
||||
@ -104,9 +104,7 @@ func (gs *gocServer) serveRpcStream(c *gin.Context) {
|
||||
gocA.Id = string(clientId)
|
||||
gs.rpcClients.Store(clientId, gocA)
|
||||
// wait for exit
|
||||
for {
|
||||
<-gocA.exitCh
|
||||
}
|
||||
<-gocA.exitCh
|
||||
}
|
||||
|
||||
func (gs *gocServer) wsping(ws *websocket.Conn, deadline time.Duration) error {
|
||||
|
Loading…
Reference in New Issue
Block a user