From 849bbda37d4a37530d284e7ef8006eccfacd99e2 Mon Sep 17 00:00:00 2001 From: lucaslin Date: Wed, 2 Nov 2022 17:28:30 +0000 Subject: Fix VPN retry timer mechanism This commit does: - Skip the new retrying request when there is a pending retrying task. Otherwise, the mRetryCount will be increased unexpectedly before the current retrying task finishes its job. - onChildOpened will call onSessionLost when MTU is invalid, and onChildOpened will be called after onIkeOpened, so if mRetryCount is reset in onIkeOpened, the mRetryCount will always start from 0. Bug: 256776571 Test: atest FrameworksNetTests:VpnTest Manual test and check the log. Change-Id: I396a3c279dc909f78c400cff1c31d77fe98cd7a6 --- services/core/java/com/android/server/connectivity/Vpn.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index 45b0f0a6d04a..8a74f4c3250d 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -2881,7 +2881,6 @@ public class Vpn { ikeConfiguration.isIkeExtensionEnabled( IkeSessionConfiguration.EXTENSION_TYPE_MOBIKE); onIkeConnectionInfoChanged(token, ikeConfiguration.getIkeSessionConnectionInfo()); - mRetryCount = 0; } /** @@ -2989,6 +2988,7 @@ public class Vpn { } doSendLinkProperties(networkAgent, lp); + mRetryCount = 0; } catch (Exception e) { Log.d(TAG, "Error in ChildOpened for token " + token, e); onSessionLost(token, e); @@ -3208,6 +3208,10 @@ public class Vpn { } private void scheduleRetryNewIkeSession() { + if (mScheduledHandleRetryIkeSessionFuture != null) { + Log.d(TAG, "There is a pending retrying task, skip the new retrying task"); + return; + } final long retryDelay = mDeps.getNextRetryDelaySeconds(mRetryCount++); Log.d(TAG, "Retry new IKE session after " + retryDelay + " seconds."); // If the default network is lost during the retry delay, the mActiveNetwork will be -- cgit v1.2.3-59-g8ed1b