aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/discover/udp.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-09-30 11:01:49 +0800
committerFelix Lange <fjl@twurst.com>2015-09-30 22:23:03 +0800
commitb4374436f331903ae1a19879aac0f37678b65f0e (patch)
treef2f9f0ba76dc4557820b4adc7eeb3b7c5113d223 /p2p/discover/udp.go
parent7977e87ce1e9ec46a8e8275f4cf53b6281c412c7 (diff)
downloaddexon-b4374436f331903ae1a19879aac0f37678b65f0e.tar
dexon-b4374436f331903ae1a19879aac0f37678b65f0e.tar.gz
dexon-b4374436f331903ae1a19879aac0f37678b65f0e.tar.bz2
dexon-b4374436f331903ae1a19879aac0f37678b65f0e.tar.lz
dexon-b4374436f331903ae1a19879aac0f37678b65f0e.tar.xz
dexon-b4374436f331903ae1a19879aac0f37678b65f0e.tar.zst
dexon-b4374436f331903ae1a19879aac0f37678b65f0e.zip
p2p/discover: fix race involving the seed node iterator
nodeDB.querySeeds was not safe for concurrent use but could be called concurrenty on multiple goroutines in the following case: - the table was empty - a timed refresh started - a lookup was started and initiated refresh These conditions are unlikely to coincide during normal use, but are much more likely to occur all at once when the user's machine just woke from sleep. The root cause of the issue is that querySeeds reused the same leveldb iterator until it was exhausted. This commit moves the refresh scheduling logic into its own goroutine (so only one refresh is ever active) and changes querySeeds to not use a persistent iterator. The seed node selection is now more random and ignores nodes that have not been contacted in the last 5 days.
Diffstat (limited to 'p2p/discover/udp.go')
-rw-r--r--p2p/discover/udp.go7
1 files changed, 0 insertions, 7 deletions
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go
index afb31ee69..8f62598f2 100644
--- a/p2p/discover/udp.go
+++ b/p2p/discover/udp.go
@@ -52,8 +52,6 @@ const (
respTimeout = 500 * time.Millisecond
sendTimeout = 500 * time.Millisecond
expiration = 20 * time.Second
-
- refreshInterval = 1 * time.Hour
)
// RPC packet types
@@ -312,10 +310,8 @@ func (t *udp) loop() {
plist = list.New()
timeout = time.NewTimer(0)
nextTimeout *pending // head of plist when timeout was last reset
- refresh = time.NewTicker(refreshInterval)
)
<-timeout.C // ignore first timeout
- defer refresh.Stop()
defer timeout.Stop()
resetTimeout := func() {
@@ -344,9 +340,6 @@ func (t *udp) loop() {
resetTimeout()
select {
- case <-refresh.C:
- go t.refresh()
-
case <-t.closing:
for el := plist.Front(); el != nil; el = el.Next() {
el.Value.(*pending).errc <- errClosed