ethernet: unregister NetworkAgent before stopping IpClient
When NetworkAgent unregisters, it invokes destroyNativeNetwork() which
deletes all routes. This process is not synchronized with IpClient. So
on an IpClient restart, it can happen that destroyNativeNetwork()
executes after the IpClient has restarted, which causes the new routes
to be deleted.
Moving NetworkAgent#unregister() to before stopping IpClient hopefully
improves this situation.
Test: atest EthernetManagerTest
Bug: 240323229
Change-Id: I68f5b35ba48d5892db0e03fa34b1884b4612485a
diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java
index 56c21eb..2196bf8 100644
--- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -586,6 +586,14 @@
}
private void stop() {
+ // Unregister NetworkAgent before stopping IpClient, so destroyNativeNetwork (which
+ // deletes routes) hopefully happens before stop() finishes execution. Otherwise, it may
+ // delete the new routes when IpClient gets restarted.
+ if (mNetworkAgent != null) {
+ mNetworkAgent.unregister();
+ mNetworkAgent = null;
+ }
+
// Invalidate all previous start requests
if (mIpClient != null) {
mIpClient.shutdown();
@@ -595,10 +603,6 @@
mIpClientCallback = null;
- if (mNetworkAgent != null) {
- mNetworkAgent.unregister();
- mNetworkAgent = null;
- }
mLinkProperties.clear();
}