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
d596bea2
Commit
d596bea2
authored
Feb 13, 2019
by
Elad
Committed by
Viktor Trón
Feb 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm: fix uptime gauge update goroutine leak by introducing cleanup functions (#19040)
parent
555b3652
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
21 deletions
+32
-21
swarm.go
swarm/swarm.go
+32
-21
No files found.
swarm/swarm.go
View file @
d596bea2
...
@@ -79,7 +79,7 @@ type Swarm struct {
...
@@ -79,7 +79,7 @@ type Swarm struct {
swap
*
swap
.
Swap
swap
*
swap
.
Swap
stateStore
*
state
.
DBStore
stateStore
*
state
.
DBStore
accountingMetrics
*
protocols
.
AccountingMetrics
accountingMetrics
*
protocols
.
AccountingMetrics
startTime
time
.
Time
cleanupFuncs
[]
func
()
error
tracerClose
io
.
Closer
tracerClose
io
.
Closer
}
}
...
@@ -106,9 +106,10 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
...
@@ -106,9 +106,10 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
}
}
self
=
&
Swarm
{
self
=
&
Swarm
{
config
:
config
,
config
:
config
,
backend
:
backend
,
backend
:
backend
,
privateKey
:
config
.
ShiftPrivateKey
(),
privateKey
:
config
.
ShiftPrivateKey
(),
cleanupFuncs
:
[]
func
()
error
{},
}
}
log
.
Debug
(
"Setting up Swarm service components"
)
log
.
Debug
(
"Setting up Swarm service components"
)
...
@@ -344,7 +345,7 @@ Start is called when the stack is started
...
@@ -344,7 +345,7 @@ Start is called when the stack is started
*/
*/
// implements the node.Service interface
// implements the node.Service interface
func
(
self
*
Swarm
)
Start
(
srv
*
p2p
.
Server
)
error
{
func
(
self
*
Swarm
)
Start
(
srv
*
p2p
.
Server
)
error
{
s
elf
.
startTime
=
time
.
Now
()
s
tartTime
:
=
time
.
Now
()
self
.
tracerClose
=
tracing
.
Closer
self
.
tracerClose
=
tracing
.
Closer
...
@@ -396,26 +397,28 @@ func (self *Swarm) Start(srv *p2p.Server) error {
...
@@ -396,26 +397,28 @@ func (self *Swarm) Start(srv *p2p.Server) error {
}()
}()
}
}
self
.
periodicallyUpdateGauges
(
)
doneC
:=
make
(
chan
struct
{}
)
s
tartCounter
.
Inc
(
1
)
s
elf
.
cleanupFuncs
=
append
(
self
.
cleanupFuncs
,
func
()
error
{
self
.
streamer
.
Start
(
srv
)
close
(
doneC
)
return
nil
return
nil
}
})
func
(
self
*
Swarm
)
periodicallyUpdateGauges
()
{
go
func
(
time
.
Time
)
{
ticker
:=
time
.
NewTicker
(
updateGaugesPeriod
)
for
{
select
{
go
func
()
{
case
<-
time
.
After
(
updateGaugesPeriod
)
:
for
range
ticker
.
C
{
uptimeGauge
.
Update
(
time
.
Since
(
startTime
)
.
Nanoseconds
())
self
.
updateGauges
()
requestsCacheGauge
.
Update
(
int64
(
self
.
netStore
.
RequestsCacheLen
()))
case
<-
doneC
:
return
}
}
}
}()
}(
startTime
)
}
func
(
self
*
Swarm
)
updateGauges
()
{
startCounter
.
Inc
(
1
)
uptimeGauge
.
Update
(
time
.
Since
(
self
.
startTime
)
.
Nanoseconds
()
)
self
.
streamer
.
Start
(
srv
)
re
questsCacheGauge
.
Update
(
int64
(
self
.
netStore
.
RequestsCacheLen
()))
re
turn
nil
}
}
// implements the node.Service interface
// implements the node.Service interface
...
@@ -452,6 +455,14 @@ func (self *Swarm) Stop() error {
...
@@ -452,6 +455,14 @@ func (self *Swarm) Stop() error {
if
self
.
stateStore
!=
nil
{
if
self
.
stateStore
!=
nil
{
self
.
stateStore
.
Close
()
self
.
stateStore
.
Close
()
}
}
for
_
,
cleanF
:=
range
self
.
cleanupFuncs
{
err
=
cleanF
()
if
err
!=
nil
{
log
.
Error
(
"encountered an error while running cleanup function"
,
"err"
,
err
)
break
}
}
return
err
return
err
}
}
...
...
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