Skip to content

Commit 8660826

Browse files
committed
builder: protect LoadInstance with a mutex
CUE is not safe for concurrent access so we protect the main LoadInstance function with a mutex lock.
1 parent 449df91 commit 8660826

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

internal/builder/instance.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010
"strings"
11+
"sync"
1112

1213
"cuelang.org/go/cue"
1314
"cuelang.org/go/cue/cuecontext"
@@ -19,6 +20,9 @@ import (
1920
"github.com/holos-run/holos/internal/util"
2021
)
2122

23+
// cue context and loading is not safe for concurrent use.
24+
var cueMutex sync.Mutex
25+
2226
// ExtractYAML extracts yaml encoded data from file paths. The data is unified
2327
// into one [cue.Value]. If a path element is a directory, all files in the
2428
// directory are loaded non-recursively.
@@ -67,6 +71,8 @@ func ExtractYAML(ctxt *cue.Context, filepaths []string) (cue.Value, error) {
6771
// extracted data values are unified with the platform configuration [cue.Value]
6872
// in the returned [Instance].
6973
func LoadInstance(path string, filepaths []string, tags []string) (*Instance, error) {
74+
cueMutex.Lock()
75+
defer cueMutex.Unlock()
7076
root, leaf, err := util.FindRootLeaf(path)
7177
if err != nil {
7278
return nil, errors.Wrap(err)

version/embedded/patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2
1+
3

0 commit comments

Comments
 (0)