You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WARNING: DATA RACE
Read at 0x00c0004a4718 by goroutine 80:
github.com/nacos-group/nacos-sdk-go/clients/naming_client.(*BeatReactor).sendInstanceBeat()
/github.com/nacos-group/nacos-sdk-go/clients/naming_client/beat_reactor.go:82 +0xcb
Previous write at 0x00c0004a4718 by goroutine 112:
[failed to restore the stack]
Goroutine 80 (running) created at:
github.com/nacos-group/nacos-sdk-go/clients/naming_client.(*BeatReactor).AddBeatInfo()
/github.com/nacos-group/nacos-sdk-go/clients/naming_client/beat_reactor.go:64 +0x39d
github.com/nacos-group/nacos-sdk-go/clients/naming_client.(*NamingClient).RegisterInstance()
/github.com/nacos-group/nacos-sdk-go/clients/naming_client/naming_client.go:122 +0x4bf
gitlab..../nacos.RegisterService()
/nacos/service.go:26 +0x195
gitlab.../internal/common/server.Register.func1()
/internal/common/server/server.go:30 +0x83
gitlab.../internal/util.GoroutineWithRecoverNotContext.func1()
/internal/util/recover.go:34 +0x5a
Source code
func (br *BeatReactor) RemoveBeatInfo(serviceName string, ip string, port uint64) {
logger.Infof("remove beat: %s@%s:%d from beat map", serviceName, ip, port)
k := buildKey(serviceName, ip, port)
data, exist := br.beatMap.Get(k)
if exist {
beatInfo := data.(*model.BeatInfo)
beatInfo.Stopped = true // write there
}
br.beatMap.Remove(k)
}
func (br *BeatReactor) sendInstanceBeat(k string, beatInfo *model.BeatInfo) {
for {
br.beatThreadSemaphore.Acquire()
//如果当前实例注销,则进行停止心跳
if beatInfo.Stopped { // read there
logger.Infof("instance[%s] stop heartBeating", k)
br.beatThreadSemaphore.Release()
return
}
//进行心跳通信
beatInterval, err := br.serviceProxy.SendBeat(*beatInfo)
if err != nil {
logger.Errorf("beat to server return error:%+v", err)
br.beatThreadSemaphore.Release()
t := time.NewTimer(beatInfo.Period)
<-t.C
continue
}
if beatInterval > 0 {
beatInfo.Period = time.Duration(time.Millisecond.Nanoseconds() * beatInterval)
}
br.beatRecordMap.Set(k, util.CurrentMillis())
br.beatThreadSemaphore.Release()
t := time.NewTimer(beatInfo.Period)
<-t.C
}
}
It's possible DeregisterInstance() write Stopped and sendInstanceBeat read Stopped at the same time.
Maybe use chan or atomic replace the bool Stopped.
The text was updated successfully, but these errors were encountered:
Using nacos-sdk-go v1.0.3
Data race log:
Source code
It's possible DeregisterInstance() write Stopped and sendInstanceBeat read Stopped at the same time.
Maybe use chan or atomic replace the bool Stopped.
The text was updated successfully, but these errors were encountered: