Skip to content

Commit ef15df1

Browse files
committed
move release to only if err == nil
1 parent 4ea0165 commit ef15df1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

coderd/parameters.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ func (api *API) handleDynamicParameters(rw http.ResponseWriter, r *http.Request,
101101

102102
// Add the file first. Calling `Release` if it fails is a no-op, so this is safe.
103103
templateFS, err := api.FileCache.Acquire(fileCtx, fileID)
104-
defer api.FileCache.Release(fileID)
105104
if err != nil {
106105
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
107106
Message: "Internal error fetching template version Terraform.",
108107
Detail: err.Error(),
109108
})
110109
return
111110
}
111+
defer api.FileCache.Release(fileID)
112112

113113
// Having the Terraform plan available for the evaluation engine is helpful
114114
// for populating values from data blocks, but isn't strictly required. If
@@ -120,14 +120,14 @@ func (api *API) handleDynamicParameters(rw http.ResponseWriter, r *http.Request,
120120

121121
if tf.CachedModuleFiles.Valid {
122122
moduleFilesFS, err := api.FileCache.Acquire(fileCtx, tf.CachedModuleFiles.UUID)
123-
defer api.FileCache.Release(tf.CachedModuleFiles.UUID)
124123
if err != nil {
125124
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
126125
Message: "Internal error fetching Terraform modules.",
127126
Detail: err.Error(),
128127
})
129128
return
130129
}
130+
defer api.FileCache.Release(tf.CachedModuleFiles.UUID)
131131

132132
templateFS = files.NewOverlayFS(templateFS, []files.Overlay{{Path: ".terraform/modules", FS: moduleFilesFS}})
133133
}

0 commit comments

Comments
 (0)