Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatal error: concurrent map iteration and map write #79

Open
guojunping opened this issue Jan 29, 2021 · 1 comment · May be fixed by #81
Open

fatal error: concurrent map iteration and map write #79

guojunping opened this issue Jan 29, 2021 · 1 comment · May be fixed by #81

Comments

@guojunping
Copy link

fatal error: concurrent map iteration and map write

goroutine 96598 [running]:
runtime.throw(0xae2e82, 0x26)
/usr/local/go/src/runtime/panic.go:1116 +0x72 fp=0xc00044ec78 sp=0xc00044ec48 pc=0x434972
runtime.mapiternext(0xc00044ed60)
/usr/local/go/src/runtime/map.go:853 +0x552 fp=0xc00044ecf8 sp=0xc00044ec78 pc=0x40f822
runtime.mapiterinit(0xa22300, 0xc000297560, 0xc00044ed60)
/usr/local/go/src/runtime/map.go:843 +0x1c4 fp=0xc00044ed18 sp=0xc00044ecf8 pc=0x40f1d4
github.com/bilibili/discovery/model.copyInstance(0xc0001348f0, 0xc00000e098)
/data/discovery/model/instance.go:103 +0x192 fp=0xc00044edd0 sp=0xc00044ed18 pc=0x991862
github.com/bilibili/discovery/model.(*Apps).InstanceInfo(0xc000542390, 0x0, 0x0, 0x0, 0xc000000001, 0xc000186860, 0x0, 0x0)
/data/discovery/model/instance.go:195 +0x255 fp=0xc00044eef8 sp=0xc00044edd0 pc=0x992135
github.com/bilibili/discovery/registry.(*Registry).Fetch(0xc000195130, 0x0, 0x0, 0xc0002301f5, 0x3, 0xc0002301e6, 0xa, 0x0, 0x1, 0xc000134188, ...)
/data/discovery/registry/registry.go:176 +0x1b0 fp=0xc00044efb0 sp=0xc00044eef8 pc=0x9997b0
github.com/bilibili/discovery/registry.(*Registry).broadcast(0xc000195130, 0xc0002301f5, 0x3, 0xc0002301e6, 0xa)
/data/discovery/registry/registry.go:257 +0x5c7 fp=0xc00044f1a0 sp=0xc00044efb0 pc=0x99ad57
github.com/bilibili/discovery/registry.(*Registry).Set(0xc000195130, 0xc000274960, 0xd60115ec06a39)
/data/discovery/registry/registry.go:288 +0xde fp=0xc00044f218 sp=0xc00044f1a0 pc=0x99b03e
github.com/bilibili/discovery/discovery.(*Discovery).Set(0xc0002e1f80, 0xbb50e0, 0xc0002745a0, 0xc000274960, 0x0, 0x7c245c673aca)
/data/discovery/discovery/register.go:96 +0x40 fp=0xc00044f280 sp=0xc00044f218 pc=0x99dd70
github.com/bilibili/discovery/http.set(0xc0002745a0)

@guojunping
Copy link
Author

guojunping commented Jan 29, 2021

解决问题
func (p *Apps) InstanceInfo(zone string, latestTime int64, status uint32) (ci *InstanceInfo, err error) {
p.lock.RLock()
defer p.lock.RUnlock()
if latestTime >= p.latestTimestamp {
err = ecode.NotModified
return
}
ci = &InstanceInfo{
LatestTimestamp: p.latestTimestamp,
Instances: make(map[string][]*Instance),
}
var ok bool
for z, app := range p.apps {
if zone == "" || z == zone {
ok = true
instances := make([]*Instance, 0)
for _, i := range app.Instances() {
app.lock.Lock()
// if up is false return all status instance
if i.filter(status) {
// if i.Status == InstanceStatusUP && i.LatestTimestamp > latestTime { // TODO(felix): increase
ni := copyInstance(i)
instances = append(instances, ni)
}
app.lock.Unlock()
}
ci.Instances[z] = instances
}
}
if !ok {
err = ecode.NothingFound
} else if len(ci.Instances) == 0 {
err = ecode.NotModified
}
return
}

@mind1949 mind1949 linked a pull request Apr 20, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant