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

android: don't set vpnService to nil when state is Stopped #523

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

kari-ts
Copy link
Collaborator

@kari-ts kari-ts commented Sep 30, 2024

We are currently setting vpnService.service to nil: -any time there’s an error with updateTUN
-when we exit out of runBackend
-if the config is the default config (aka when the ipn state is Stopped)

When it gets set to nil, we don’t handle state or config updates by calling updateTUN until after startVPN is called again. The second case never happens because there’s no condition to break out of the loop in runBackend and ctx is uncancelable per the doc for context.Background() In the third case, we should not establish the VPN; the state is already in the correct Stopped state, but there’s no need to set the service to nil and prevent updateTUN from being called. The quick settings tile bug is caused by this third case, where because the saved prefs starts the app up in the Stopped state, the config is set to the default config, and the service is set to nil, and we can't updateTUN until there’s another startVPN call.

This PR:
-cleans up the updateTUN error handling to be more consistent -removes the IPNService parameter from updateTUN so that vpnService.service is not set to nil in the third case

Fixes tailscale/tailscale#12489

Copy link
Contributor

@nickkhyl nickkhyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few small improvements.

libtailscale/backend.go Outdated Show resolved Hide resolved
libtailscale/backend.go Outdated Show resolved Hide resolved
libtailscale/backend.go Show resolved Hide resolved
libtailscale/backend.go Outdated Show resolved Hide resolved
@kari-ts kari-ts force-pushed the kari/nilservice branch 2 times, most recently from 46e57af to f497b01 Compare September 30, 2024 21:27
@kari-ts
Copy link
Collaborator Author

kari-ts commented Sep 30, 2024

Thanks for the review! I made another change to use stopSelf instead of stopForeground for when we disconnect the VPN; the latter only stops the service when more memory is needed, but when there is an error we want to kill the service completely

We are currently setting vpnService.service to nil:
-any time there’s an error with updateTUN
-when we exit out of runBackend
-if the config is the default config (aka when the ipn state is Stopped)

When it gets set to nil, we don’t handle state or config updates by calling updateTUN until after startVPN is called again.
The second case never happens because there’s no condition to break out of the loop in runBackend and ctx is uncancelable per the doc for context.Background()
In the third case, we should not establish the VPN; the state is already in the correct Stopped state, but there’s no need to set the service to nil and prevent updateTUN from being called. The quick settings tile bug is caused by this third case, where because the saved prefs starts the app up in the Stopped state, the config is set to the default config, and the service is set to nil, and we can't updateTUN until there’s another startVPN call.

This PR:
-cleans up the updateTUN error handling to be more consistent
-removes the IPNService parameter from updateTUN so that vpnService.service is not set to nil in the third case
-updates IPNService to use stopSelf and not stopForeground when we disconnect the VPN; the latter only disconnects if there is a memory need

Fixes tailscale/tailscale#12489

Signed-off-by: kari-ts <[email protected]>
@kari-ts kari-ts merged commit c10aca7 into main Sep 30, 2024
4 checks passed
@kari-ts kari-ts deleted the kari/nilservice branch September 30, 2024 22:47
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.

Android quick tile toggle doesn't activate Tailscale on version 1.68
2 participants