mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-26 00:29:06 +02:00
[client] Serialize Android tunnel reconfiguration callbacks
The Android route notifier and the DNS search-domain notifier both delivered OnNetworkChanged from a fire-and-forget goroutine per update. Two updates in quick succession could reach the Java side reordered: the TUN rebuild handler applies them in arrival order and compares against the last applied parameters, so a stale route set delivered last won as the final TUN state. This is the same reordering hazard fixed for iOS in #6454. Wrap the Android network change listener into the shared tunnelnotifier FIFO introduced in #6870, the same way RunOniOS does, and deliver both notifiers synchronously into it. Enqueueing is non-blocking, a single delivery goroutine preserves order, and calls into Java never overlap. Also stop hasRouteDiff from sorting the notifier's shared route slices in place; compare sorted copies instead.
This commit is contained in:
@@ -113,11 +113,14 @@ func (c *ConnectClient) RunOnAndroid(
|
|||||||
stateFilePath string,
|
stateFilePath string,
|
||||||
cacheDir string,
|
cacheDir string,
|
||||||
) error {
|
) error {
|
||||||
|
notifier := tunnelnotifier.New(networkChangeListener, nil)
|
||||||
|
defer notifier.Close()
|
||||||
|
|
||||||
// in case of non Android os these variables will be nil
|
// in case of non Android os these variables will be nil
|
||||||
mobileDependency := MobileDependency{
|
mobileDependency := MobileDependency{
|
||||||
TunAdapter: tunAdapter,
|
TunAdapter: tunAdapter,
|
||||||
IFaceDiscover: iFaceDiscover,
|
IFaceDiscover: iFaceDiscover,
|
||||||
NetworkChangeListener: networkChangeListener,
|
NetworkChangeListener: notifier,
|
||||||
HostDNSAddresses: dnsAddresses,
|
HostDNSAddresses: dnsAddresses,
|
||||||
DnsReadyListener: dnsReadyListener,
|
DnsReadyListener: dnsReadyListener,
|
||||||
StateFilePath: stateFilePath,
|
StateFilePath: stateFilePath,
|
||||||
|
|||||||
@@ -51,7 +51,5 @@ func (n *notifier) notify() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func(l listener.NetworkChangeListener) {
|
n.listener.OnNetworkChanged("")
|
||||||
l.OnNetworkChanged("")
|
|
||||||
}(n.listener)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,9 +79,7 @@ func (n *Notifier) notify() {
|
|||||||
|
|
||||||
routeStrings := n.routesToStrings(allRoutes)
|
routeStrings := n.routesToStrings(allRoutes)
|
||||||
sort.Strings(routeStrings)
|
sort.Strings(routeStrings)
|
||||||
go func(l listener.NetworkChangeListener) {
|
n.listener.OnNetworkChanged(strings.Join(routeStrings, ","))
|
||||||
l.OnNetworkChanged(strings.Join(routeStrings, ","))
|
|
||||||
}(n.listener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterStatic(routes []*route.Route) []*route.Route {
|
func filterStatic(routes []*route.Route) []*route.Route {
|
||||||
@@ -103,16 +101,11 @@ func (n *Notifier) routesToStrings(routes []*route.Route) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) hasRouteDiff(a []*route.Route, b []*route.Route) bool {
|
func (n *Notifier) hasRouteDiff(a []*route.Route, b []*route.Route) bool {
|
||||||
slices.SortFunc(a, func(x, y *route.Route) int {
|
as := n.routesToStrings(a)
|
||||||
return strings.Compare(x.NetString(), y.NetString())
|
bs := n.routesToStrings(b)
|
||||||
})
|
sort.Strings(as)
|
||||||
slices.SortFunc(b, func(x, y *route.Route) int {
|
sort.Strings(bs)
|
||||||
return strings.Compare(x.NetString(), y.NetString())
|
return !slices.Equal(as, bs)
|
||||||
})
|
|
||||||
|
|
||||||
return !slices.EqualFunc(a, b, func(x, y *route.Route) bool {
|
|
||||||
return x.NetString() == y.NetString()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) GetInitialRouteRanges() []string {
|
func (n *Notifier) GetInitialRouteRanges() []string {
|
||||||
|
|||||||
Reference in New Issue
Block a user