Skip to content

Commit

Permalink
chore: add mutex for the artifact installation
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 26, 2024
1 parent e6010e7 commit 14df190
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/runtime/kclvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"sync"
"time"

"github.com/gofrs/flock"
Expand All @@ -26,6 +27,8 @@ func init() {
g_KclvmRoot = findKclvmRoot()
}

var mutex = &sync.Mutex{}

func installKclArtifact() {
// Get the install lib path.
path := path.LibPath()
Expand All @@ -36,6 +39,8 @@ func installKclArtifact() {
// Acquire a file lock for process synchronization
lockPath := filepath.Join(path, "init.lock")
fileLock := flock.New(lockPath)
mutex.Lock()
defer mutex.Unlock()
lockCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
locked, err := fileLock.TryLockContext(lockCtx, time.Second)
Expand Down

0 comments on commit 14df190

Please sign in to comment.