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

tunnel: stop vpn adapter when another app takes over the vpn #1549

Closed

Conversation

SaadAhmedGit
Copy link

@SaadAhmedGit SaadAhmedGit commented Jun 15, 2024

fixes: #1545

This small change fixes the issue mentioned in the referenced issue. When another app takes over the VPN, onRevoke() method of the VpnService() is called which wasn't overriden to call stopVpnAdapter() which closes the tunnel.

Overriding onRevoke() to call stopVpnAdapter() ensures the tunnel is closed gracefully when another app starts the VPN.

@ignoramous
Copy link
Collaborator

Access to the variable vpnAdapter isn't synchronised, and so the check for vpnAdapter == null in the io coroutine is suspect.

Anyhow, thanks for the fix. I'll tag Hussain for review.

@SaadAhmedGit
Copy link
Author

SaadAhmedGit commented Jun 17, 2024

Access to the variable vpnAdapter isn't synchronised, and so the check for vpnAdapter == null in the io coroutine is suspect.

But super.onRevoke() only calls stopself() which doesn't use vpnAdapter. Even in signalStopService(), stopSelf() doesn't wait for stopVpnAdapter() to finish.

fun signalStopService(userInitiated: Boolean = true) {
if (!userInitiated) notifyUserOnVpnFailure()
stopVpnAdapter()
stopSelf()
Logger.i(LOG_TAG_VPN, "stopped vpn adapter and vpn service")
}

@ignoramous
Copy link
Collaborator

ignoramous commented Jun 17, 2024

vpnAdapter == null check is problematic regardless of what calls what, since one coroutine setting vpnAdapter to null will not be known to another coroutine unless there is a lock/serialisation (via Volatile).

Don't worry about it too much, we'll take a look at it as a separate issue.

@SaadAhmedGit
Copy link
Author

Closing because already fixed.

Reference

@hussainmohd-a
Copy link
Collaborator

@SaadAhmedGit Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Wireguard Bug] - Listen port isn't released when another VPN app attempts to start a VPN on the same port
3 participants