mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-01 04:21:29 +02:00
[client] Publish the network selection event on a partial failure
Returning early on error was correct while an error meant nothing had happened. A partial failure now changes the selection and the routing table, so returning first left the change with no trace in the event log or the UI, even though the new state had already been broadcast.
This commit is contained in:
@@ -160,12 +160,16 @@ func (s *Server) SelectNetworks(_ context.Context, req *proto.SelectNetworksRequ
|
|||||||
return nil, fmt.Errorf("no route manager")
|
return nil, fmt.Errorf("no route manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selectErr error
|
||||||
if req.GetAll() {
|
if req.GetAll() {
|
||||||
routeManager.SelectAllRoutes()
|
routeManager.SelectAllRoutes()
|
||||||
} else if err := routeManager.SelectRoutes(toNetIDs(req.GetNetworkIDs()), req.GetAppend()); err != nil {
|
} else {
|
||||||
return nil, err
|
selectErr = routeManager.SelectRoutes(toNetIDs(req.GetNetworkIDs()), req.GetAppend())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A partial failure (e.g. an unknown ID in the request) still changes the selection,
|
||||||
|
// so the event must be published regardless of selectErr, or the change leaves no
|
||||||
|
// trace in the event log/UI even though it already reached the routing table.
|
||||||
s.statusRecorder.PublishEvent(
|
s.statusRecorder.PublishEvent(
|
||||||
proto.SystemEvent_INFO,
|
proto.SystemEvent_INFO,
|
||||||
proto.SystemEvent_SYSTEM,
|
proto.SystemEvent_SYSTEM,
|
||||||
@@ -178,6 +182,10 @@ func (s *Server) SelectNetworks(_ context.Context, req *proto.SelectNetworksRequ
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if selectErr != nil {
|
||||||
|
return nil, selectErr
|
||||||
|
}
|
||||||
|
|
||||||
return &proto.SelectNetworksResponse{}, nil
|
return &proto.SelectNetworksResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,12 +212,16 @@ func (s *Server) DeselectNetworks(_ context.Context, req *proto.SelectNetworksRe
|
|||||||
return nil, fmt.Errorf("no route manager")
|
return nil, fmt.Errorf("no route manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deselectErr error
|
||||||
if req.GetAll() {
|
if req.GetAll() {
|
||||||
routeManager.DeselectAllRoutes()
|
routeManager.DeselectAllRoutes()
|
||||||
} else if err := routeManager.DeselectRoutes(toNetIDs(req.GetNetworkIDs())); err != nil {
|
} else {
|
||||||
return nil, err
|
deselectErr = routeManager.DeselectRoutes(toNetIDs(req.GetNetworkIDs()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A partial failure (e.g. an unknown ID in the request) still changes the selection,
|
||||||
|
// so the event must be published regardless of deselectErr, or the change leaves no
|
||||||
|
// trace in the event log/UI even though it already reached the routing table.
|
||||||
s.statusRecorder.PublishEvent(
|
s.statusRecorder.PublishEvent(
|
||||||
proto.SystemEvent_INFO,
|
proto.SystemEvent_INFO,
|
||||||
proto.SystemEvent_SYSTEM,
|
proto.SystemEvent_SYSTEM,
|
||||||
@@ -222,6 +234,10 @@ func (s *Server) DeselectNetworks(_ context.Context, req *proto.SelectNetworksRe
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if deselectErr != nil {
|
||||||
|
return nil, deselectErr
|
||||||
|
}
|
||||||
|
|
||||||
return &proto.SelectNetworksResponse{}, nil
|
return &proto.SelectNetworksResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user