Skip to content

Commit af2a56a

Browse files
bug: lock when setting up runtimes
1 parent d6ae14d commit af2a56a

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

pkg/repos/runtimes/busybox/busybox.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"path/filepath"
1515
"runtime"
1616
"strings"
17+
"sync"
1718

1819
runtimeEnv "github.com/gptscript-ai/gptscript/pkg/env"
1920
"github.com/gptscript-ai/gptscript/pkg/hash"
@@ -27,6 +28,7 @@ var releasesData []byte
2728
const downloadURL = "https://github.com/gptscript-ai/busybox-w32/releases/download/%s"
2829

2930
type Runtime struct {
31+
runtimeSetupLock sync.Mutex
3032
}
3133

3234
func (r *Runtime) ID() string {
@@ -75,6 +77,9 @@ func (r *Runtime) getReleaseAndDigest() (string, string, error) {
7577
}
7678

7779
func (r *Runtime) getRuntime(ctx context.Context, cwd string) (string, error) {
80+
r.runtimeSetupLock.Lock()
81+
defer r.runtimeSetupLock.Unlock()
82+
7883
url, sha, err := r.getReleaseAndDigest()
7984
if err != nil {
8085
return "", err

pkg/repos/runtimes/golang/golang.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"path/filepath"
1818
"runtime"
1919
"strings"
20+
"sync"
2021

2122
"github.com/gptscript-ai/gptscript/pkg/config"
2223
"github.com/gptscript-ai/gptscript/pkg/debugcmd"
@@ -34,6 +35,8 @@ const downloadURL = "https://go.dev/dl/"
3435
type Runtime struct {
3536
// version something like "1.22.1"
3637
Version string
38+
39+
runtimeSetupLock sync.Mutex
3740
}
3841

3942
func (r *Runtime) ID() string {
@@ -355,6 +358,9 @@ func (r *Runtime) binDir(rel string) string {
355358
}
356359

357360
func (r *Runtime) getRuntime(ctx context.Context, cwd string) (string, error) {
361+
r.runtimeSetupLock.Lock()
362+
defer r.runtimeSetupLock.Unlock()
363+
358364
url, sha, err := r.getReleaseAndDigest()
359365
if err != nil {
360366
return "", err

pkg/repos/runtimes/node/node.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path/filepath"
1313
"runtime"
1414
"strings"
15+
"sync"
1516

1617
"github.com/gptscript-ai/gptscript/pkg/debugcmd"
1718
runtimeEnv "github.com/gptscript-ai/gptscript/pkg/env"
@@ -34,6 +35,8 @@ type Runtime struct {
3435
Version string
3536
// If true this is the version that will be used for python or python3
3637
Default bool
38+
39+
runtimeSetupLock sync.Mutex
3740
}
3841

3942
func (r *Runtime) ID() string {
@@ -175,6 +178,9 @@ func (r *Runtime) binDir(rel string) (string, error) {
175178
}
176179

177180
func (r *Runtime) getRuntime(ctx context.Context, cwd string) (string, error) {
181+
r.runtimeSetupLock.Lock()
182+
defer r.runtimeSetupLock.Unlock()
183+
178184
url, sha, err := r.getReleaseAndDigest()
179185
if err != nil {
180186
return "", err

pkg/repos/runtimes/python/python.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"path/filepath"
1414
"runtime"
15+
"sync"
1516

1617
"github.com/gptscript-ai/gptscript/pkg/debugcmd"
1718
runtimeEnv "github.com/gptscript-ai/gptscript/pkg/env"
@@ -42,6 +43,8 @@ type Runtime struct {
4243
Version string
4344
// If true this is the version that will be used for python or python3
4445
Default bool
46+
47+
runtimeSetupLock sync.Mutex
4548
}
4649

4750
func (r *Runtime) ID() string {
@@ -234,6 +237,9 @@ func (r *Runtime) setupUV(ctx context.Context, tmp string) error {
234237
}
235238

236239
func (r *Runtime) getRuntime(ctx context.Context, cwd string) (string, error) {
240+
r.runtimeSetupLock.Lock()
241+
defer r.runtimeSetupLock.Unlock()
242+
237243
url, sha, err := r.getReleaseAndDigest()
238244
if err != nil {
239245
return "", err

0 commit comments

Comments
 (0)