diff --git a/pkg/runtime/node/build.go b/pkg/runtime/node/build.go index a52b6a3f3..1cf6a771c 100644 --- a/pkg/runtime/node/build.go +++ b/pkg/runtime/node/build.go @@ -23,8 +23,8 @@ var forceExternal = []string{ } func (r *Runtime) Build(ctx context.Context, input *runtime.BuildInput) (*runtime.BuildOutput, error) { - r.lock.Acquire(ctx, 1) - defer r.lock.Release(1) + r.concurrency.Acquire(ctx, 1) + defer r.concurrency.Release(1) var properties NodeProperties json.Unmarshal(input.Properties, &properties) @@ -132,14 +132,14 @@ func (r *Runtime) Build(ctx context.Context, input *runtime.BuildInput) (*runtim options.Target = properties.ESBuild.Target } - buildContext, ok := r.contexts[input.FunctionID] + buildContext, ok := r.contexts.Load(input.FunctionID) if !ok { buildContext, _ = esbuild.Context(options) - r.contexts[input.FunctionID] = buildContext + r.contexts.Store(input.FunctionID, buildContext) } - result := buildContext.Rebuild() - r.results[input.FunctionID] = result + result := buildContext.(esbuild.BuildContext).Rebuild() + r.results.Store(input.FunctionID, result) errors := []string{} for _, error := range result.Errors { text := error.Text diff --git a/pkg/runtime/node/node.go b/pkg/runtime/node/node.go index 625370ba1..a9a36c4ab 100644 --- a/pkg/runtime/node/node.go +++ b/pkg/runtime/node/node.go @@ -58,10 +58,10 @@ var LoaderToString = []string{ } type Runtime struct { - cfgPath string - contexts map[string]esbuild.BuildContext - results map[string]esbuild.BuildResult - lock *semaphore.Weighted + cfgPath string + contexts sync.Map + results sync.Map + concurrency *semaphore.Weighted } func New() *Runtime { @@ -70,9 +70,9 @@ func New() *Runtime { weight, _ = strconv.ParseInt(flag.SST_BUILD_CONCURRENCY, 10, 64) } return &Runtime{ - contexts: map[string]esbuild.BuildContext{}, - results: map[string]esbuild.BuildResult{}, - lock: semaphore.NewWeighted(weight), + contexts: sync.Map{}, + results: sync.Map{}, + concurrency: semaphore.NewWeighted(weight), } }