Skip to content

Commit

Permalink
diag: thread-safety step4 - remove dedicated shutdown listener gorout…
Browse files Browse the repository at this point in the history
…ine (#11137)

reason: 
- we already have 1 goroutine for saving data:
```
func (d *DiagnosticClient) runSaveProcess(rootCtx context.Context) {
	ticker := time.NewTicker(5 * time.Minute)
	go func() {
		for {
			select {
			case <-ticker.C:
				d.SaveData()
			case <-rootCtx.Done():
				ticker.Stop()
				return
			}
		}
	}()
}
```
no reason to save it from one more goroutine. just save it right here -
in `case <-rootCtx.Done()` section. less concurrency - better.

rootContext already subscribed to sigterm
  • Loading branch information
AskAlexSharov authored Jul 13, 2024
1 parent 2d96dbb commit 12c2732
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions erigon-lib/diagnostics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ package diagnostics
import (
"context"
"net/http"
"os"
"os/signal"
"path/filepath"
"sync"
"syscall"
"time"

"github.com/c2h5oh/datasize"
Expand Down Expand Up @@ -120,33 +117,21 @@ func (d *DiagnosticClient) Setup() {
d.setupResourcesUsageDiagnostics(rootCtx)
d.setupSpeedtestDiagnostics(rootCtx)
d.runSaveProcess(rootCtx)
d.runStopNodeListener(rootCtx)

//d.logDiagMsgs()
}

func (d *DiagnosticClient) runStopNodeListener(rootCtx context.Context) {
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
select {
case <-ch:
d.SaveData()
case <-rootCtx.Done():
}
}()
}

// Save diagnostic data by time interval to reduce save events
func (d *DiagnosticClient) runSaveProcess(rootCtx context.Context) {
ticker := time.NewTicker(5 * time.Minute)
go func() {
defer ticker.Stop()
for {
select {
case <-ticker.C:
d.SaveData()
case <-rootCtx.Done():
ticker.Stop()
d.SaveData()
return
}
}
Expand Down

0 comments on commit 12c2732

Please sign in to comment.