Skip to content

Commit

Permalink
Fix renaming consistency between DB and runtime state
Browse files Browse the repository at this point in the history
  • Loading branch information
ttpreport committed Mar 4, 2024
1 parent 368890b commit 90282d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
assets/artifacts/*.zip
4 changes: 2 additions & 2 deletions internal/core/agents/agentlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (agents *Agents) Create(config *config.Config, session *yamux.Session) (*Ag
}

func (agents *Agents) Rename(oldAlias, newAlias string) error {
agents.mutex.RLock()
defer agents.mutex.RUnlock()
agents.mutex.Lock()
defer agents.mutex.Unlock()

agent := agents.active[oldAlias]
if agent == nil {
Expand Down
13 changes: 7 additions & 6 deletions internal/core/tuns/tunlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,18 @@ func (tuns *Tuns) Rename(oldAlias, newAlias string) error {
defer tuns.mutex.Unlock()

if tun, ok := tuns.active[oldAlias]; ok {
if err := tuns.store.RenameTun(oldAlias, newAlias); err != nil {
slog.Warn("Couldn't rename tun in storage",
slog.Any("reason", err),
)
return err
}

tun.Alias = newAlias

events.EventStream <- events.Event{Type: events.TunRenamed, Data: *tun}
}

if err := tuns.store.RenameTun(oldAlias, newAlias); err != nil {
slog.Warn("Couldn't rename tun from storage",
slog.Any("reason", err),
)
}

return nil
}

Expand Down

0 comments on commit 90282d0

Please sign in to comment.