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

fix: add quiescenceRun flag to avoid render loops #2010

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
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
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
Loading