Browse Source

fix race

pull/456/head
Anton Kaliaev 8 years ago
parent
commit
5ab8ca0868
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      addrbook.go

+ 6
- 4
addrbook.go View File

@ -135,15 +135,15 @@ func (a *AddrBook) OnStart() error {
return nil return nil
} }
func (a *AddrBook) Wait() {
a.wg.Wait()
}
// OnStop implements Service. // OnStop implements Service.
func (a *AddrBook) OnStop() { func (a *AddrBook) OnStop() {
a.BaseService.OnStop() a.BaseService.OnStop()
} }
func (a *AddrBook) Wait() {
a.wg.Wait()
}
func (a *AddrBook) AddOurAddress(addr *NetAddress) { func (a *AddrBook) AddOurAddress(addr *NetAddress) {
a.mtx.Lock() a.mtx.Lock()
defer a.mtx.Unlock() defer a.mtx.Unlock()
@ -320,6 +320,8 @@ type addrBookJSON struct {
func (a *AddrBook) saveToFile(filePath string) { func (a *AddrBook) saveToFile(filePath string) {
log.Info("Saving AddrBook to file", "size", a.Size()) log.Info("Saving AddrBook to file", "size", a.Size())
a.mtx.Lock()
defer a.mtx.Unlock()
// Compile Addrs // Compile Addrs
addrs := []*knownAddress{} addrs := []*knownAddress{}
for _, ka := range a.addrLookup { for _, ka := range a.addrLookup {


Loading…
Cancel
Save