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

diag: thread-safety step2 - unlock mutex in defer #11135

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
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
41 changes: 21 additions & 20 deletions erigon-lib/diagnostics/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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 @@ -382,26 +402,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 @@ -28,8 +28,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 @@ -34,6 +34,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 @@ -49,14 +52,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) HardwareInfo() HardwareInfo {
Expand Down
Loading