Skip to content

Commit

Permalink
Merge pull request PelicanPlatform#1652 from h2zh/stop-ticker
Browse files Browse the repository at this point in the history
cleanup all tickers when they're no longer needed
  • Loading branch information
jhiemstrawisc authored Oct 17, 2024
2 parents 89e1d38 + 0cd9d74 commit 4f7e010
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions broker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func ConnectToOrigin(ctx context.Context, brokerUrl, prefix, originName string)
// Wait for the origin to callback to the cache's return endpoint; that HTTP handler
// will write to the channel we originally posted.
tck := time.NewTicker(20 * time.Second)
defer tck.Stop()
log.Debugf("Cache waiting for up to 20 seconds for the origin %s to callback", originName)
select {
case <-ctx.Done():
Expand Down
1 change: 1 addition & 0 deletions cmd/progress_bars.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (pb *progressBars) launchDisplay(ctx context.Context) {

tickDuration := 200 * time.Millisecond
ticker := time.NewTicker(tickDuration)
defer ticker.Stop()
pbMap := make(map[string]*progressBar)
for {
select {
Expand Down
1 change: 1 addition & 0 deletions director/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ func AdvertiseOSDF(ctx context.Context) error {

func PeriodicCacheReload(ctx context.Context) {
ticker := time.NewTicker(param.Federation_TopologyReloadInterval.GetDuration())
defer ticker.Stop()
for {
select {
case <-ticker.C:
Expand Down
1 change: 1 addition & 0 deletions director/maxmind.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func periodicMaxMindReload(ctx context.Context) {

// Update once every other day
ticker := time.NewTicker(48 * time.Hour)
defer ticker.Stop()
for {
select {
case <-ticker.C:
Expand Down
1 change: 1 addition & 0 deletions launcher_utils/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func LaunchPeriodicAdvertise(ctx context.Context, egrp *errgroup.Group, servers
doAdvertise(ctx, servers)

ticker := time.NewTicker(1 * time.Minute)
defer ticker.Stop()
egrp.Go(func() error {

for {
Expand Down
1 change: 1 addition & 0 deletions launcher_utils/register_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func RegisterNamespaceWithRetry(ctx context.Context, egrp *errgroup.Group, prefi

egrp.Go(func() error {
ticker := time.NewTicker(retryInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
Expand Down
2 changes: 2 additions & 0 deletions local_cache/local_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ func (sc *LocalCache) runMux() error {
activeJobs := make(map[string]*activeDownload)
jobPath := make(map[string]string)
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
clientClosed := false
for {
lenResults := len(tmpResults)
Expand Down Expand Up @@ -761,6 +762,7 @@ func (sc *LocalCache) updateConfig() error {
// Periodically update the cache configuration from the registry
func (sc *LocalCache) periodicUpdateConfig() error {
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
for {
select {
case <-sc.ctx.Done():
Expand Down
1 change: 1 addition & 0 deletions server_utils/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func LaunchPeriodicDirectorTimeout(ctx context.Context, egrp *errgroup.Group, nC
return
}
directorTimeoutTicker := time.NewTicker(directorTimeoutDuration)
defer directorTimeoutTicker.Stop()

egrp.Go(func() error {
for {
Expand Down
1 change: 1 addition & 0 deletions server_utils/server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func LaunchWatcherMaintenance(ctx context.Context, dirPaths []string, descriptio
}
cases := make([]reflect.SelectCase, select_count)
ticker := time.NewTicker(sleepTime)
defer ticker.Stop()
cases[0].Dir = reflect.SelectRecv
cases[0].Chan = reflect.ValueOf(ticker.C)
cases[1].Dir = reflect.SelectRecv
Expand Down
1 change: 1 addition & 0 deletions utils/ca_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func LaunchPeriodicWriteCABundle(ctx context.Context, egrpKey string, filename s
}
egrp.Go(func() error {
ticker := time.NewTicker(sleepTime)
defer ticker.Stop()
for {
select {
case <-ticker.C:
Expand Down
1 change: 1 addition & 0 deletions web_ui/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
// Periodically re-read the htpasswd file used for password-based authentication
func periodicAuthDBReload(ctx context.Context) error {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
Expand Down
1 change: 1 addition & 0 deletions web_ui/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ func ConfigureEmbeddedPrometheus(ctx context.Context, engine *gin.Engine) error
return errors.New("Refresh interval is non-positive value. Stop reloading.")
}
ticker := time.NewTicker(refreshInterval)
defer ticker.Stop()
for {
select {
case <-cancel:
Expand Down

0 comments on commit 4f7e010

Please sign in to comment.