mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network/stream: fix sync between NewRegistry goroutine and Close method
This commit is contained in:
parent
7579260cc0
commit
77b0599fd1
1 changed files with 17 additions and 6 deletions
|
|
@ -178,7 +178,10 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy
|
|||
|
||||
for {
|
||||
select {
|
||||
case i := <-in:
|
||||
case i, ok := <-in:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-out:
|
||||
default:
|
||||
|
|
@ -193,14 +196,22 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy
|
|||
return out
|
||||
}
|
||||
|
||||
go func() {
|
||||
// wait for kademlia table to be healthy
|
||||
time.Sleep(options.SyncUpdateDelay)
|
||||
|
||||
kad := streamer.delivery.kad
|
||||
// get notification channels from Kademlia before returning
|
||||
// from this function to avoid race with Close method and
|
||||
// the goroutine created below
|
||||
depthC := latestIntC(kad.NeighbourhoodDepthC())
|
||||
addressBookSizeC := latestIntC(kad.AddrCountC())
|
||||
|
||||
go func() {
|
||||
// wait for kademlia table to be healthy
|
||||
// but return if Registry is closed before
|
||||
select {
|
||||
case <-time.After(options.SyncUpdateDelay):
|
||||
case <-quit:
|
||||
return
|
||||
}
|
||||
|
||||
// initial requests for syncing subscription to peers
|
||||
streamer.updateSyncing()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue