Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm: fix a data race on startTime #18511

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (
)

var (
startTime time.Time
updateGaugesPeriod = 5 * time.Second
startCounter = metrics.NewRegisteredCounter("stack,start", nil)
stopCounter = metrics.NewRegisteredCounter("stack,stop", nil)
Expand All @@ -80,6 +79,7 @@ type Swarm struct {
swap *swap.Swap
stateStore *state.DBStore
accountingMetrics *protocols.AccountingMetrics
startTime time.Time

tracerClose io.Closer
}
Expand Down Expand Up @@ -344,7 +344,7 @@ Start is called when the stack is started
*/
// implements the node.Service interface
func (self *Swarm) Start(srv *p2p.Server) error {
startTime = time.Now()
self.startTime = time.Now()

self.tracerClose = tracing.Closer

Expand Down Expand Up @@ -414,7 +414,7 @@ func (self *Swarm) periodicallyUpdateGauges() {
}

func (self *Swarm) updateGauges() {
uptimeGauge.Update(time.Since(startTime).Nanoseconds())
uptimeGauge.Update(time.Since(self.startTime).Nanoseconds())
requestsCacheGauge.Update(int64(self.netStore.RequestsCacheLen()))
}

Expand Down