Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
49927650
Commit
49927650
authored
Apr 28, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discover: fix goroutine leak due to blocking on sync.Once
parent
437cf4b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
13 deletions
+24
-13
database.go
p2p/discover/database.go
+23
-12
table.go
p2p/discover/table.go
+1
-1
No files found.
p2p/discover/database.go
View file @
49927650
...
@@ -177,23 +177,34 @@ func (db *nodeDB) updateNode(node *Node) error {
...
@@ -177,23 +177,34 @@ func (db *nodeDB) updateNode(node *Node) error {
return
db
.
lvl
.
Put
(
makeKey
(
node
.
ID
,
nodeDBDiscoverRoot
),
blob
,
nil
)
return
db
.
lvl
.
Put
(
makeKey
(
node
.
ID
,
nodeDBDiscoverRoot
),
blob
,
nil
)
}
}
// ensureExpirer is a small helper method ensuring that the data expiration
// mechanism is running. If the expiration goroutine is already running, this
// method simply returns.
//
// The goal is to start the data evacuation only after the network successfully
// bootstrapped itself (to prevent dumping potentially useful seed nodes). Since
// it would require significant overhead to exactly trace the first successful
// convergence, it's simpler to "ensure" the correct state when an appropriate
// condition occurs (i.e. a successful bonding), and discard further events.
func
(
db
*
nodeDB
)
ensureExpirer
()
{
db
.
runner
.
Do
(
func
()
{
go
db
.
expirer
()
})
}
// expirer should be started in a go routine, and is responsible for looping ad
// expirer should be started in a go routine, and is responsible for looping ad
// infinitum and dropping stale data from the database.
// infinitum and dropping stale data from the database.
func
(
db
*
nodeDB
)
expirer
()
{
func
(
db
*
nodeDB
)
expirer
()
{
db
.
runner
.
Do
(
func
()
{
tick
:=
time
.
Tick
(
nodeDBCleanupCycle
)
tick
:=
time
.
Tick
(
nodeDBCleanupCycle
)
for
{
for
{
select
{
select
{
case
<-
tick
:
case
<-
tick
:
if
err
:=
db
.
expireNodes
();
err
!=
nil
{
if
err
:=
db
.
expireNodes
();
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"Failed to expire nodedb items: %v"
,
err
)
glog
.
V
(
logger
.
Error
)
.
Infof
(
"Failed to expire nodedb items: %v"
,
err
)
}
case
<-
db
.
quit
:
return
}
}
case
<-
db
.
quit
:
return
}
}
}
)
}
}
}
// expireNodes iterates over the database and deletes all nodes that have not
// expireNodes iterates over the database and deletes all nodes that have not
...
...
p2p/discover/table.go
View file @
49927650
...
@@ -335,7 +335,7 @@ func (tab *Table) ping(id NodeID, addr *net.UDPAddr) error {
...
@@ -335,7 +335,7 @@ func (tab *Table) ping(id NodeID, addr *net.UDPAddr) error {
}
}
// Pong received, update the database and return
// Pong received, update the database and return
tab
.
db
.
updateLastPong
(
id
,
time
.
Now
())
tab
.
db
.
updateLastPong
(
id
,
time
.
Now
())
go
tab
.
db
.
e
xpirer
()
tab
.
db
.
ensureE
xpirer
()
return
nil
return
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment