Background checks get their own copy of the answers
The dashboard, mirror, review, users, rooms, tokens and update checks copied the config with *s.cfg, which still shares the Components, Values and Overrides maps. They read those maps (VarsYAML, DNSRecords) while the UI writes them: leaving Settings or saving a Fine-tune value during a check could abort the app with "concurrent map iteration and map write". config.Clone copies the maps and slices too, and the deploy runner and history snapshot use it as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
87e848dede
commit
c8ab8fddd3
13 files changed
+39
-19
No files matched your search
@@ -177,6 +177,19 @@ func Fresh() *Config {
|
||||
return c
|
||||
}
|
||||
|
||||
// Clone is a copy that shares no maps or slices with c, for work in the
|
||||
// background while c is still being edited.
|
||||
func (c *Config) Clone() *Config {
|
||||
cp := *c
|
||||
cp.Components, cp.Values, cp.Overrides = maps.Clone(c.Components), maps.Clone(c.Values), maps.Clone(c.Overrides)
|
||||
cp.FederateOnly, cp.FederateNever = slices.Clone(c.FederateOnly), slices.Clone(c.FederateNever)
|
||||
if c.Deployed != nil {
|
||||
d := *c.Deployed
|
||||
cp.Deployed = &d
|
||||
}
|
||||
return &cp
|
||||
}
|
||||
|
||||
// Load returns the saved configuration, or fresh answers on first run.
|
||||
// A file that can't be parsed is moved aside to <file>.broken-<time>
|
||||
// first, so its secrets aren't overwritten by the fresh ones on the next
|
||||
|
||||
@@ -261,3 +261,13 @@ func TestLoadMovesBrokenFileAside(t *testing.T) {
|
||||
t.Fatal("loaded nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneSharesNothing(t *testing.T) {
|
||||
c := Default()
|
||||
c.FederateOnly = []string{"a.org"}
|
||||
cp := c.Clone()
|
||||
cp.Components["x"], cp.Values["y"], cp.Overrides["z"], cp.FederateOnly[0] = true, "1", "2", "b.org"
|
||||
if c.Components["x"] || c.Values["y"] != "" || c.Overrides["z"] != "" || c.FederateOnly[0] != "a.org" {
|
||||
t.Errorf("clone shares state with the original: %+v", c)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -281,8 +280,7 @@ func Start(ctx context.Context, cfg *config.Config, opts Options) <-chan Event {
|
||||
// A migration and blackout mirror picks change the run's config; the
|
||||
// caller applies those changes through events.
|
||||
if opts.Action == ActionMigrate || opts.Action == ActionDryRun || cfg.Sources.Blackout {
|
||||
cp := *cfg
|
||||
cfg = &cp
|
||||
cfg = cfg.Clone()
|
||||
}
|
||||
if opts.Action == ActionDryRun {
|
||||
cfg.PlaybookDir = DryRunDir(cfg)
|
||||
@@ -466,8 +464,7 @@ func (r *Runner) writeInventory(step Step) error {
|
||||
|
||||
// The playbook was just updated and may have renamed settings since the
|
||||
// config was loaded; a copy, as the UI reads c while this runs.
|
||||
fixed := *c
|
||||
fixed.Values, fixed.Overrides = maps.Clone(c.Values), maps.Clone(c.Overrides)
|
||||
fixed := c.Clone()
|
||||
for _, n := range fixed.RenameOld(c.PlaybookDir) {
|
||||
r.note(step, "renamed "+n)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func RecordDeploy(c *config.Config, commit string) error {
|
||||
if err := os.MkdirAll(dir, 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
snap := *c
|
||||
snap := c.Clone()
|
||||
snap.PinnedCommit = ""
|
||||
if err := snap.SaveFile(filepath.Join(dir, "config.json")); err != nil {
|
||||
return err
|
||||
|
||||
@@ -92,7 +92,7 @@ func (s *dashboardScreen) refresh() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
s.loading = true
|
||||
cfg, srv := *s.cfg, s.server
|
||||
cfg, srv := *s.cfg.Clone(), s.server
|
||||
certs := s.certsNow || s.st == nil || len(s.st.Certs) == 0 || time.Since(s.certsAt) > certsEvery
|
||||
s.certsNow = false
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
|
||||
@@ -100,7 +100,7 @@ func (s *mirrorsScreen) check() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
s.loading = [3]bool{true, true, true}
|
||||
cfg, srv := *s.cfg, s.server
|
||||
cfg, srv := *s.cfg.Clone(), s.server
|
||||
part := func(n int, fn func(r *mirrorsResult)) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
var r mirrorsResult
|
||||
|
||||
@@ -110,7 +110,7 @@ func (s *roomsScreen) saveToken(t string) {
|
||||
func (s *roomsScreen) reload() tea.Cmd {
|
||||
s.busy, s.err = true, nil
|
||||
s.gen++
|
||||
cfg, login, srv, gen := *s.cfg, s.login(), s.server, s.gen
|
||||
cfg, login, srv, gen := *s.cfg.Clone(), s.login(), s.server, s.gen
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
defer cancel()
|
||||
@@ -122,7 +122,7 @@ func (s *roomsScreen) reload() tea.Cmd {
|
||||
// do runs a change, then reloads the list.
|
||||
func (s *roomsScreen) do(info string, fn func(ctx context.Context, c *config.Config, login *deploy.AdminLogin) error) tea.Cmd {
|
||||
s.busy, s.err, s.info = true, nil, ""
|
||||
cfg, login := *s.cfg, s.login()
|
||||
cfg, login := *s.cfg.Clone(), s.login()
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
@@ -202,7 +202,7 @@ func (s *reviewScreen) runChecks() tea.Cmd {
|
||||
}
|
||||
s.checking = true
|
||||
s.gen++
|
||||
cfg, gen := *s.cfg, s.gen
|
||||
cfg, gen := *s.cfg.Clone(), s.gen
|
||||
ctx, stop := context.WithTimeout(context.Background(), 40*time.Second)
|
||||
s.stop = stop
|
||||
s.stage, s.since = "the server", time.Now()
|
||||
@@ -289,7 +289,7 @@ func (s *reviewScreen) update(msg tea.Msg) tea.Cmd {
|
||||
s.setPreview()
|
||||
return nil
|
||||
}
|
||||
cfg := *s.cfg
|
||||
cfg := *s.cfg.Clone()
|
||||
return func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -418,7 +418,7 @@ func (s *manageScreen) choose(id string) tea.Cmd {
|
||||
}
|
||||
}
|
||||
}
|
||||
cfg := *s.cfg
|
||||
cfg := *s.cfg.Clone()
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -136,7 +136,7 @@ func (s *updatesScreen) enter(c *config.Config) tea.Cmd {
|
||||
|
||||
func (s *updatesScreen) check() tea.Cmd {
|
||||
s.loading, s.err, s.ch = true, nil, nil
|
||||
cfg := *s.cfg
|
||||
cfg := *s.cfg.Clone()
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
@@ -381,7 +381,7 @@ func (s *tuningScreen) key(k tea.KeyMsg) tea.Cmd {
|
||||
if s.err != nil {
|
||||
if k.String() == "f" && !s.fetching {
|
||||
s.fetching = true
|
||||
cfg := *s.cfg
|
||||
cfg := *s.cfg.Clone()
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
@@ -95,7 +95,7 @@ func (s *tokensScreen) enter(c *config.Config) tea.Cmd {
|
||||
func (s *tokensScreen) reload() tea.Cmd {
|
||||
s.busy, s.err = true, nil
|
||||
s.gen++
|
||||
cfg, srv, gen := *s.cfg, s.server, s.gen
|
||||
cfg, srv, gen := *s.cfg.Clone(), s.server, s.gen
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
@@ -107,7 +107,7 @@ func (s *tokensScreen) reload() tea.Cmd {
|
||||
// do runs a change, then reloads the list.
|
||||
func (s *tokensScreen) do(info string, fn func(ctx context.Context, c *config.Config) error) tea.Cmd {
|
||||
s.busy, s.err, s.info = true, nil, ""
|
||||
cfg := *s.cfg
|
||||
cfg := *s.cfg.Clone()
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
@@ -163,7 +163,7 @@ func (s *usersScreen) reload() tea.Cmd {
|
||||
s.syncing = true
|
||||
}
|
||||
s.gen++
|
||||
cfg, login, srv, gen := *s.cfg, s.login, s.server, s.gen
|
||||
cfg, login, srv, gen := *s.cfg.Clone(), s.login, s.server, s.gen
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
defer cancel()
|
||||
@@ -223,7 +223,7 @@ func (s *usersScreen) loginForm() {
|
||||
|
||||
func (s *usersScreen) run(op *userOp) tea.Cmd {
|
||||
s.busy, s.info, s.password, s.err = true, "", "", nil
|
||||
cfg, login := *s.cfg, s.login
|
||||
cfg, login := *s.cfg.Clone(), s.login
|
||||
return tea.Batch(s.spin.Tick, func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
Reference in new issue
Block a user