Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: fix data race in agentscripts.Runner#17630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletionsagent/agentscripts/agentscripts.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ import (
"os/user"
"path/filepath"
"sync"
"sync/atomic"
"time"

"github.com/google/uuid"
Expand DownExpand Up@@ -104,7 +103,6 @@ type Runner struct {
closed chan struct{}
closeMutex sync.Mutex
cron *cron.Cron
initialized atomic.Bool
scripts []runnerScript
dataDir string
scriptCompleted ScriptCompletedFunc
Expand All@@ -113,6 +111,9 @@ type Runner struct {
// execute startup scripts, and scripts on a cron schedule. Both will increment
// this counter.
scriptsExecuted *prometheus.CounterVec

initMutex sync.Mutex
initialized bool
}

// DataDir returns the directory where scripts data is stored.
Expand DownExpand Up@@ -154,10 +155,12 @@ func WithPostStartScripts(scripts ...codersdk.WorkspaceAgentScript) InitOption {
// It also schedules any scripts that have a schedule.
// This function must be called before Execute.
func (r *Runner) Init(scripts []codersdk.WorkspaceAgentScript, scriptCompleted ScriptCompletedFunc, opts ...InitOption) error {
if r.initialized.Load() {
r.initMutex.Lock()
defer r.initMutex.Unlock()
if r.initialized {
return xerrors.New("init: already initialized")
}
r.initialized.Store(true)
r.initialized =true
r.scripts = toRunnerScript(scripts...)
r.scriptCompleted = scriptCompleted
for _, opt := range opts {
Expand DownExpand Up@@ -227,6 +230,18 @@ const (

// Execute runs a set of scripts according to a filter.
func (r *Runner) Execute(ctx context.Context, option ExecuteOption) error {
initErr := func() error {
r.initMutex.Lock()
defer r.initMutex.Unlock()
if !r.initialized {
return xerrors.New("execute: not initialized")
}
return nil
}()
if initErr != nil {
return initErr
}

var eg errgroup.Group
for _, script := range r.scripts {
runScript := (option == ExecuteStartScripts && script.RunOnStart) ||
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp