mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-09 15:09:08 +02:00
Fail modifyPeers before any removal when a peer's state is unavailable
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user