Skip to content

Commit 85bbae6

Browse files
Callum Styanclaude
andcommitted
fix: add Close() to RenderCache interface for proper cleanup
The renderCache field in StoreReconciler was using the concrete type *RenderCacheImpl instead of the RenderCache interface, preventing proper cleanup of cache goroutines. Changes: - Add Close() method to RenderCache interface - Implement Close() as no-op in noopRenderCache - Update StoreReconciler.renderCache to use interface type - Update wsbuilder.Builder.renderCache to use interface type - Remove unnecessary nil check in reconciler Stop() method This ensures all render cache cleanup goroutines are properly stopped when reconcilers are stopped, fixing goleak test failures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent bea92ad commit 85bbae6

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

coderd/dynamicparameters/render.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var ErrTemplateVersionNotReady = xerrors.New("template version job not finished"
3939
type RenderCache interface {
4040
get(templateVersionID, ownerID uuid.UUID, parameters map[string]string) (*preview.Output, bool)
4141
put(templateVersionID, ownerID uuid.UUID, parameters map[string]string, output *preview.Output)
42+
Close()
4243
}
4344

4445
// noopRenderCache is a no-op implementation of RenderCache that doesn't cache anything.
@@ -52,6 +53,10 @@ func (noopRenderCache) put(uuid.UUID, uuid.UUID, map[string]string, *preview.Out
5253
// no-op
5354
}
5455

56+
func (noopRenderCache) Close() {
57+
// no-op
58+
}
59+
5560
// loader is used to load the necessary coder objects for rendering a template
5661
// version's parameters. The output is a Renderer, which is the object that uses
5762
// the cached objects to render the template version's parameters.

coderd/wsbuilder/wsbuilder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type Builder struct {
8989
workspaceTags *map[string]string
9090

9191
// renderCache caches template rendering results
92-
renderCache *dynamicparameters.RenderCacheImpl
92+
renderCache dynamicparameters.RenderCache
9393

9494
prebuiltWorkspaceBuildStage sdkproto.PrebuiltWorkspaceBuildStage
9595
verifyNoLegacyParametersOnce bool
@@ -258,7 +258,7 @@ func (b Builder) TemplateVersionPresetID(id uuid.UUID) Builder {
258258

259259
// RenderCache sets the render cache to use for template rendering.
260260
// This allows multiple workspace builds to share cached render results.
261-
func (b Builder) RenderCache(cache *dynamicparameters.RenderCacheImpl) Builder {
261+
func (b Builder) RenderCache(cache dynamicparameters.RenderCache) Builder {
262262
// nolint: revive
263263
b.renderCache = cache
264264
return b

enterprise/coderd/prebuilds/reconcile.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type StoreReconciler struct {
6161
reconciliationDuration prometheus.Histogram
6262

6363
// renderCache caches template rendering results to avoid expensive re-parsing
64-
renderCache *dynamicparameters.RenderCacheImpl
64+
renderCache dynamicparameters.RenderCache
6565
}
6666

6767
var _ prebuilds.ReconciliationOrchestrator = &StoreReconciler{}
@@ -294,9 +294,7 @@ func (c *StoreReconciler) Stop(ctx context.Context, cause error) {
294294
}
295295

296296
// Close the render cache to stop its cleanup goroutine
297-
if c.renderCache != nil {
298-
c.renderCache.Close()
299-
}
297+
c.renderCache.Close()
300298
}
301299

302300
// ReconcileAll will attempt to resolve the desired vs actual state of all templates which have presets with prebuilds configured.

0 commit comments

Comments
 (0)