Skip to content

Commit 72e46df

Browse files
janosdshulyak
authored andcommitted
swarm: fix a data race on startTime (ethereum#18511)
(cherry picked from commit fa34429)
1 parent b43e5e7 commit 72e46df

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

swarm/swarm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import (
5656
)
5757

5858
var (
59-
startTime time.Time
6059
updateGaugesPeriod = 5 * time.Second
6160
startCounter = metrics.NewRegisteredCounter("stack,start", nil)
6261
stopCounter = metrics.NewRegisteredCounter("stack,stop", nil)
@@ -80,6 +79,7 @@ type Swarm struct {
8079
swap *swap.Swap
8180
stateStore *state.DBStore
8281
accountingMetrics *protocols.AccountingMetrics
82+
startTime time.Time
8383

8484
tracerClose io.Closer
8585
}
@@ -344,7 +344,7 @@ Start is called when the stack is started
344344
*/
345345
// implements the node.Service interface
346346
func (self *Swarm) Start(srv *p2p.Server) error {
347-
startTime = time.Now()
347+
self.startTime = time.Now()
348348

349349
self.tracerClose = tracing.Closer
350350

@@ -414,7 +414,7 @@ func (self *Swarm) periodicallyUpdateGauges() {
414414
}
415415

416416
func (self *Swarm) updateGauges() {
417-
uptimeGauge.Update(time.Since(startTime).Nanoseconds())
417+
uptimeGauge.Update(time.Since(self.startTime).Nanoseconds())
418418
requestsCacheGauge.Update(int64(self.netStore.RequestsCacheLen()))
419419
}
420420

0 commit comments

Comments
 (0)