fix: make sure ping shuts down

This commit is contained in:
Zane Schepke 2025-01-02 17:10:32 -05:00
parent 48c01aa0e3
commit a5898d4ad1
1 changed files with 9 additions and 5 deletions

View File

@ -193,6 +193,7 @@ constructor(
onTunnelStop(tunnelConfig) onTunnelStop(tunnelConfig)
updateTunnelState(it, null) updateTunnelState(it, null)
}.onFailure { }.onFailure {
clearJobsAndStats()
Timber.e(it) Timber.e(it)
} }
} }
@ -313,8 +314,7 @@ constructor(
override fun cancelActiveTunnelJobs() { override fun cancelActiveTunnelJobs() {
statsJob?.cancelWithMessage("Tunnel stats job cancelled") statsJob?.cancelWithMessage("Tunnel stats job cancelled")
tunnelChangesJob?.cancelWithMessage("Tunnel changes job cancelled") tunnelChangesJob?.cancelWithMessage("Tunnel changes job cancelled")
pingJob?.cancelWithMessage("Ping job cancelled") cancelPingJobs()
networkJob?.cancelWithMessage("Network job cancelled")
} }
override fun startActiveTunnelJobs() { override fun startActiveTunnelJobs() {
@ -326,6 +326,7 @@ constructor(
} }
private fun startPingJobs() { private fun startPingJobs() {
cancelPingJobs()
pingJob = startPingJob() pingJob = startPingJob()
networkJob = startNetworkJob() networkJob = startNetworkJob()
} }
@ -373,8 +374,7 @@ constructor(
with(_vpnState.value.tunnelConfig) { with(_vpnState.value.tunnelConfig) {
if (this == null) return if (this == null) return
if (!isPingEnabled && pingJob?.isActive == true) { if (!isPingEnabled && pingJob?.isActive == true) {
pingJob?.cancelWithMessage("Ping job cancelled") cancelPingJobs()
networkJob?.cancelWithMessage("Network job cancelled")
return return
} }
restartPingJob() restartPingJob()
@ -382,9 +382,13 @@ constructor(
} }
private fun restartPingJob() { private fun restartPingJob() {
cancelPingJobs()
startPingJobs()
}
private fun cancelPingJobs() {
pingJob?.cancelWithMessage("Ping job cancelled") pingJob?.cancelWithMessage("Ping job cancelled")
networkJob?.cancelWithMessage("Network job cancelled") networkJob?.cancelWithMessage("Network job cancelled")
startPingJobs()
} }
private fun startTunnelConfigChangesJob() = applicationScope.launch(ioDispatcher) { private fun startTunnelConfigChangesJob() = applicationScope.launch(ioDispatcher) {