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 is sometimes stopped twice #1213

Merged
merged 4 commits into from
Feb 7, 2025
Merged

Conversation

diegoreymendez
Copy link
Contributor

@diegoreymendez diegoreymendez commented Feb 5, 2025

Task/Issue URL: https://app.asana.com/0/1207603085593419/1209322889682604/f

iOS PR: duckduckgo/iOS#3928
macOS PR: duckduckgo/macos-browser#3829

What kind of version bump will this require?: Patch

Description

Fixes an issue where the tunnel is being stopped twice.

Testing

Please refer to the platform-specific PRs for testing instructions.


Internal references:

Software Engineering Expectations
Technical Design Template

@diegoreymendez diegoreymendez self-assigned this Feb 5, 2025
@@ -700,7 +700,6 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
}

Logger.networkProtection.error("🔴 Stopping VPN due to no auth token")
await cancelTunnel(with: TunnelError.startingTunnelWithoutAuthToken)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to cancel the tunnel if we're throwing an error below, which is the right way to cancel startup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, yeah good catch.

case .vpnAccessRevoked:
return "VPN disconnected due to expired subscription"
case .couldNotGenerateTunnelConfiguration(let internalError):
return "Failed to generate a tunnel configuration: \(internalError.localizedDescription)"
case .simulateTunnelFailureError:
return "Simulated a tunnel error as requested"
case .tokenReset:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Differentiating a specific case that was previously reported as startingTunnelWithoutAuthToken.

}
case .reset:
// This case should in theory not be possible, but it's ideal to have this in place
// in case an error in the controller on the client side allows it.
try await tokenHandler.removeToken()
throw TunnelError.startingTunnelWithoutAuthToken
try? await tokenHandler.removeToken()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if this fails, this isn't the real failure reason - the real failure reason is the token is being removed which, as described above, is an abnormal scenario. The removal failing shouldn't be the error we get.

@@ -603,22 +608,22 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
try await tokenHandler.refreshToken()
} catch {
Logger.networkProtection.fault("Error force-refreshing token container: \(error, privacy: .public)\n \(newTokenContainer.refreshToken, privacy: .public)")
throw TunnelError.startingTunnelWithoutAuthToken
throw TunnelError.startingTunnelWithoutAuthToken(internalError: error)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just taking advantage that there's underlying error info.

@diegoreymendez diegoreymendez merged commit ab64a66 into main Feb 7, 2025
7 checks passed
@diegoreymendez diegoreymendez deleted the diego/fix-tunnel-stop-issues branch February 7, 2025 09:07
diegoreymendez added a commit to duckduckgo/iOS that referenced this pull request Feb 7, 2025
Task/Issue URL:
https://app.asana.com/0/1207603085593419/1209322889682604/f

macOS PR: duckduckgo/macos-browser#3829
BSK PR: duckduckgo/BrowserServicesKit#1213

**Description**:

Fixes an issue where the tunnel is being stopped twice.
diegoreymendez added a commit to duckduckgo/macos-browser that referenced this pull request Feb 7, 2025
Task/Issue URL:
https://app.asana.com/0/1207603085593419/1209322889682604/f

iOS PR: duckduckgo/iOS#3928
BSK PR: duckduckgo/BrowserServicesKit#1213

**Description**:

Fixes an issue where the tunnel is being stopped twice.
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.

2 participants