Skip to content

Commit

Permalink
diag: thread-safety step2 - unlock mutex in defer (#11135)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jul 13, 2024
1 parent b1c60ad commit 2d96dbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
41 changes: 21 additions & 20 deletions erigon-lib/diagnostics/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ func (d *DiagnosticClient) updateSnapshotStageStats(stats SyncStageStats, subSta

d.syncStages[idxs.Stage].SubStages[idxs.SubStage].Stats = stats
}
func (d *DiagnosticClient) saveSnapshotStageStatsToDB() {
d.mu.Lock()
defer d.mu.Unlock()
err := d.db.Update(d.ctx, func(tx kv.RwTx) error {
err := SnapshotFillDBUpdater(d.syncStats.SnapshotFillDB)(tx)
if err != nil {
return err
}

err = StagesListUpdater(d.syncStages)(tx)
if err != nil {
return err
}

return nil
})
if err != nil {
log.Debug("[Diagnostics] Failed to update snapshot download info", "err", err)
}
}

func (d *DiagnosticClient) runSegmentDownloadingListener(rootCtx context.Context) {
go func() {
Expand Down Expand Up @@ -384,26 +404,7 @@ func (d *DiagnosticClient) runFillDBListener(rootCtx context.Context) {
TimeLeft: "unknown",
Progress: fmt.Sprintf("%d%%", (info.Stage.Current*100)/info.Stage.Total),
}, "Fill DB from snapshots")

d.mu.Lock()
err := d.db.Update(d.ctx, func(tx kv.RwTx) error {
err := SnapshotFillDBUpdater(d.syncStats.SnapshotFillDB)(tx)
if err != nil {
return err
}

err = StagesListUpdater(d.syncStages)(tx)
if err != nil {
return err
}

return nil
})

if err != nil {
log.Warn("[Diagnostics] Failed to update snapshot download info", "err", err)
}
d.mu.Unlock()
d.saveSnapshotStageStatsToDB()
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/diagnostics/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (d *DiagnosticClient) setupSpeedtestDiagnostics(rootCtx context.Context) {
go func() {
if d.speedTest {
d.networkSpeedMutex.Lock()
defer d.networkSpeedMutex.Unlock()
d.networkSpeed = d.runSpeedTest(rootCtx)
d.networkSpeedMutex.Unlock()
}
}()
}
Expand Down
7 changes: 3 additions & 4 deletions erigon-lib/diagnostics/sys_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var (
)

func (d *DiagnosticClient) setupSysInfoDiagnostics() {
d.mu.Lock()
defer d.mu.Unlock()

sysInfo := GetSysInfo(d.dataDirPath)

var funcs []func(tx kv.RwTx) error
Expand All @@ -52,14 +55,10 @@ func (d *DiagnosticClient) setupSysInfoDiagnostics() {

return nil
})

if err != nil {
log.Warn("[Diagnostics] Failed to update system info", "err", err)
}

d.mu.Lock()
d.hardwareInfo = sysInfo
d.mu.Unlock()
}

func (d *DiagnosticClient) HardwareInfoJson(w io.Writer) {
Expand Down

0 comments on commit 2d96dbb

Please sign in to comment.