Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions libs/aitools/autoinstall/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ const (
// and rewritten.
stateLockFileName = "auto-install.json.lock"

// stateLockWait bounds the wait for the state lock. A live holder keeps it
// only to read or rewrite a small file.
stateLockWait = time.Second

// lockRetryInterval is how often a held lock is tried again.
lockRetryInterval = 10 * time.Millisecond
)
Expand Down Expand Up @@ -181,6 +177,10 @@ func lock(ctx context.Context, name string, wait time.Duration) (unlock func(),
}
}

// stateLockWait bounds the wait for the state lock. A live holder keeps it
// only to read or rewrite a small file. Tests that queue many holders raise it.
var stateLockWait = time.Second

// errLockHeld is the error of tryLockFile when another process holds the lock.
var errLockHeld = errors.New("held by another CLI process")

Expand Down
7 changes: 7 additions & 0 deletions libs/aitools/autoinstall/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func TestTryLockExcludesOtherRuns(t *testing.T) {
func TestRecordKeepsConcurrentOptOut(t *testing.T) {
ctx := env.WithUserHomeDir(t.Context(), t.TempDir())

// The 21 writers take the lock one at a time, and on a slow runner each
// holds it long enough that the last ones would give up after the
// default wait.
orig := stateLockWait
t.Cleanup(func() { stateLockWait = orig })
stateLockWait = time.Minute

// Without the state lock, a Record that read the state before the opt-out
// was saved would write opted_out=false back.
var wg sync.WaitGroup
Expand Down
Loading