Skip to content

Commit

Permalink
fix: add quiescenceRun flag to avoid render loops
Browse files Browse the repository at this point in the history
When quiescence is configured and there are multiple templates, they
will trigger eachothers quiescence timers indefinitely. This can be
avoided by not ticking the timer of other templates when an individual
template's timer fires.
  • Loading branch information
mismithhisler committed Dec 12, 2024
1 parent a7fb634 commit e60eab9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions manager/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ type Runner struct {
// quiescenceMap is the map of templates to their quiescence timers.
// quiescenceCh is the channel where templates report returns from quiescence
// fires.
// quiescenceRun is the template that was triggered to render via
// its respective timer. This flag is an optimization used to avoid infinite
// rendering when multiple templates exist.
quiescenceMap map[string]*quiescence
quiescenceCh chan *template.Template
quiescenceRun *template.Template

// dedup is the deduplication manager if enabled
dedup *DedupManager
Expand Down Expand Up @@ -474,6 +478,7 @@ func (r *Runner) Start() {
// Remove the quiescence for this template from the map. This will force
// the upcoming Run call to actually evaluate and render the template.
log.Printf("[DEBUG] (runner) received template %q from quiescence", tmpl.ID())
r.quiescenceRun = tmpl
delete(r.quiescenceMap, tmpl.ID())

case c := <-childExitCh:
Expand Down Expand Up @@ -667,6 +672,9 @@ func (r *Runner) Run() error {
}
}

// Always reset quiescenceRun in case this run was triggered by a quiescence timer
r.quiescenceRun = nil

// Perform the diff and update the known dependencies.
r.diffAndUpdateDeps(runCtx.depsMap)

Expand Down Expand Up @@ -892,6 +900,13 @@ func (r *Runner) runTemplate(tmpl *template.Template, runCtx *templateRunCtx) (*
}
}

if r.quiescenceRun != nil && r.quiescenceRun != tmpl {
// During a run triggered via quiescence, mark any template not corresponding to
// the quiescence timer as ForQuiescence, signaling it was purposefully skipped.
event.ForQuiescence = true
return event, nil
}

// If quiescence is activated, start/update the timers and loop back around.
// We do not want to render the templates yet.
if q, ok := r.quiescenceMap[tmpl.ID()]; ok {
Expand Down

0 comments on commit e60eab9

Please sign in to comment.