Skip to content

Commit

Permalink
Fix SQLiteConstraintException spike crashes (#4558)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/488551667048375/1207351226753468/f

### Description
Gracefully stop the VPN in case of `code 1555 SQLITE_CONSTRAINT_PRIMARYKEY` db error

### Steps to test this PR
NA, just code review
  • Loading branch information
aitorvs authored May 20, 2024
1 parent 013041b commit f078095
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ class TrackerBlockingVpnService : VpnService(), CoroutineScope by MainScope(), V
deviceShieldPixels.reportVpnStartAttempt()
dnsChangeCallback.unregister()

vpnServiceStateStatsDao.insert(createVpnState(state = ENABLING))
runCatching {
vpnServiceStateStatsDao.insert(createVpnState(state = ENABLING))
}.onFailure {
stopVpn(VpnStopReason.ERROR, false)
}

logcat { "VPN log: Starting VPN" }
val restarting = activeTun != null
Expand Down Expand Up @@ -382,7 +386,12 @@ class TrackerBlockingVpnService : VpnService(), CoroutineScope by MainScope(), V
}

// lastly set the VPN state to enabled
vpnServiceStateStatsDao.insert(createVpnState(state = ENABLED))
runCatching {
vpnServiceStateStatsDao.insert(createVpnState(state = ENABLED))
}.onFailure {
// onVpnStarted or onVpnReconfigured already called, ie. hasVpnAlreadyStarted = true
stopVpn(VpnStopReason.ERROR, true)
}

// This is something temporary while we confirm whether we're able to fix the moto g issues with appTP
// see https://app.asana.com/0/488551667048375/1203410036713941/f for more info
Expand Down Expand Up @@ -597,7 +606,9 @@ class TrackerBlockingVpnService : VpnService(), CoroutineScope by MainScope(), V
}

// Set the state to DISABLED here, then call the on stop/failure callbacks
vpnServiceStateStatsDao.insert(createVpnState(state = VpnServiceState.DISABLED, stopReason = reason))
runCatching {
vpnServiceStateStatsDao.insert(createVpnState(state = VpnServiceState.DISABLED, stopReason = reason))
}

vpnStateServiceReference?.let {
runCatching { unbindService(vpnStateServiceConnection).also { vpnStateServiceReference = null } }
Expand Down

0 comments on commit f078095

Please sign in to comment.