Fail modifyPeers before any removal when a peer's state is unavailable

This commit is contained in:
Viktor Liu
2026-08-20 14:19:47 +02:00
parent 787d07b57f
commit 5ae19bc0e4
+10 -5
View File
@@ -863,15 +863,20 @@ func (e *Engine) modifyPeers(peersUpdate []*mgmProto.RemotePeerConfig) error {
} }
} }
// second, close all modified connections and remove them from the state map, // second, look up the activation state of all modified peers before removing
// remembering which of them were active // any of them, so an unavailable state leaves the current connections intact
active := make(map[string]bool, len(modified)) active := make(map[string]bool, len(modified))
for _, p := range modified { for _, p := range modified {
peerPubKey := p.GetWgPubKey() peerPubKey := p.GetWgPubKey()
if state, err := e.statusRecorder.GetPeer(peerPubKey); err == nil { state, err := e.statusRecorder.GetPeer(peerPubKey)
active[peerPubKey] = state.ConnStatus != peer.StatusIdle if err != nil {
return fmt.Errorf("get status of modified peer %s: %w", peerPubKey, err)
} }
if err := e.removePeer(peerPubKey); err != nil { active[peerPubKey] = state.ConnStatus != peer.StatusIdle
}
// then close all modified connections and remove them from the state map
for _, p := range modified {
if err := e.removePeer(p.GetWgPubKey()); err != nil {
return err return err
} }
} }