Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPN-6407: 15 minutes between daemon server switches #9972

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.os.CountDownTimer
import mozilla.telemetry.glean.GleanTimerId
import org.mozilla.firefox.vpn.daemon.GleanMetrics.ConnectionHealth
import org.mozilla.firefox.vpn.daemon.GleanMetrics.Session
import java.time.LocalDateTime
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

Expand All @@ -35,6 +36,9 @@ class ConnectionHealth(service: VPNService) {
private var lastHealthStatus = ConnectionStability.Stable
private var connectionHealthTimerId: GleanTimerId? = null

private val SERVER_SWITCH_COOLDOWN_MINUTES: Long = 15
private var nextPossibleServerSwitch = LocalDateTime.now().plusMinutes(SERVER_SWITCH_COOLDOWN_MINUTES)

var mActive = false
var mVPNNetwork: Network? = null
var mWorker: ExecutorService = Executors.newSingleThreadExecutor()
Expand Down Expand Up @@ -242,11 +246,18 @@ class ConnectionHealth(service: VPNService) {
if (fallbackServerIsReachable) {
recordMetrics(ConnectionStability.Unstable)

if (LocalDateTime.now() < nextPossibleServerSwitch) {
Log.i(TAG, "Want to switch servers, but it has not been enough time since last server switch")
taskDone()
return@Runnable
}

Log.i(TAG, "Switch to fallback VPN server")
// We the server is online but the connection broke up, let's rest it
mService.mainLooper.run {
// Silent server switch to the same server
// Silent server switch to a different server in same geo
Session.daemonSilentServerSwitch.record()
nextPossibleServerSwitch = LocalDateTime.now().plusMinutes(SERVER_SWITCH_COOLDOWN_MINUTES)
mService.reconnect(true)
}
mResetUsed = true
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/ios/ConnectionHealth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConnectionHealth {
private let toleranceTime = 1.0 // 1 seconds
private var timer: Timer?
private var nextPossibleServerSwitch = Date()
private let serverSwitchCooldownMinutes: TimeInterval = 60*5 // 5 minutes
private let serverSwitchCooldownMinutes: TimeInterval = 60*15 // 15 minutes

private var lastHealthStatus: ConnectionStability = .pending
private var connectionHealthTimerId: GleanTimerId? = nil
Expand Down
Loading