Skip to content

KM-13372 Fail to trigger allow VPN permission - #219

Closed
kp-diego-trevisan wants to merge 3 commits into
masterfrom
KM-13372-pia-fail-to-trigger-allow-vpn-permission
Closed

KM-13372 Fail to trigger allow VPN permission#219
kp-diego-trevisan wants to merge 3 commits into
masterfrom
KM-13372-pia-fail-to-trigger-allow-vpn-permission

Conversation

@kp-diego-trevisan

@kp-diego-trevisan kp-diego-trevisan commented Dec 17, 2025

Copy link
Copy Markdown
Collaborator

Summary

This is not a fix yet because it's uncertain what is causing the issue.
Instead it adds async support and adds logs to help us visualize which step for installation is failing whenever it happens again.

@kp-diego-trevisan
kp-diego-trevisan force-pushed the KM-13372-pia-fail-to-trigger-allow-vpn-permission branch from fcf3ea4 to 60006e6 Compare December 23, 2025 15:08
@kp-diego-trevisan
kp-diego-trevisan force-pushed the KM-13372-pia-fail-to-trigger-allow-vpn-permission branch from 60006e6 to 554390d Compare March 6, 2026 08:31
@kp-diego-trevisan
kp-diego-trevisan marked this pull request as ready for review March 6, 2026 08:32
@claude

claude Bot commented Mar 6, 2026

Copy link
Copy Markdown

Claude finished @kp-diego-trevisan's task —— View job


Code Review Complete ✅

Completed comprehensive review of the VPN permission installation async migration and logging improvements.

Todo List:

  • Read and analyze all changed files
  • Review async implementation patterns
  • Check error handling and logging approach
  • Assess threading and memory management
  • Evaluate security considerations
  • Review test coverage and mock updates
  • Identify impacted features and testing flows
  • Provide comprehensive review feedback

Code Quality & Best Practices

✅ Strengths

  • Proper async/await migration: The new async install(force:) method follows modern Swift concurrency patterns
  • Backward compatibility: Deprecated callback-based install(force:_:) method properly bridges to async implementation
  • Consistent error handling: Proper error propagation through the async chain
  • Good separation of concerns: tvOS wrapper classes maintain clean abstractions

⚠️ Areas for Improvement

1. Error Handling & Logging - DefaultVPNProvider.swift:148-215

// Current implementation loses specific error information
catch {
    log.error("VPN install failed with error: \(error.localizedDescription)")
    continuation.resume(throwing: error)
}

Issue: Generic catch blocks lose valuable debugging information. Consider adding more specific error context.

Suggestion: Add step-specific logging to identify where failures occur:

log.info("VPN install starting - Force: \(forceInstall), VPN Type: \(newVPNType)")
// ... then log each major step
log.info("VPN install: Profile configuration obtained")
log.info("VPN install: Saving profile configuration")

2. Thread Safety - DefaultVPNProvider.swift:174-197

The profile save operation and callback handling could potentially race:

profile.save(withConfiguration: configuration, force: forcedStatuses) { error in
    // Multiple async operations here without explicit synchronization
    if let error { ... }
    self.activeProfile = profile
    // ... more operations
}

Recommendation: Ensure all database/state updates happen on the main queue or use proper synchronization.

3. Resource Management - DefaultVPNProvider.swift:149

Using withCheckedThrowingContinuation is correct, but consider timeout handling for network operations that might hang indefinitely.

4. Magic Numbers - VPNPermissionViewController.swift:97

alert.addCancelActionWithTitle(L10n.Localizable.Global.ok) {
    self.submit() // Recursively calls submit() - potential infinite loop
}

Critical Issue: This creates potential infinite recursion if VPN install keeps failing.

Security Considerations

✅ Security Strengths

  • Proper authorization checks: All install operations verify user login status
  • Secure credential handling: Uses password references instead of plain passwords
  • Network extension security: Maintains proper separation between app and extensions

⚠️ Security Concerns

  1. Error information exposure: Some error messages might leak internal implementation details
  2. Retry mechanism vulnerability: The recursive retry in VPNPermissionViewController could be exploited for DoS

Threading & Performance

✅ Good Practices

  • Main actor usage: VPNPermissionViewController.swift:73 properly uses @MainActor
  • Async bridging: Callback-to-async bridge is implemented correctly

⚠️ Threading Issues

  • Mixed threading models: Some operations mix callback and async patterns without clear thread guarantees
  • Database access: Multiple database operations without explicit queue management

Test Coverage Assessment

✅ Positive Changes

  • Mock updates: MockVPNProvider and VpnConfigurationProviderTypeMock properly implement new async methods
  • Protocol compliance: All mocks correctly implement the updated protocols

❌ Missing Test Coverage

  1. No async-specific tests: Need tests verifying async error propagation
  2. Threading tests: Missing tests for concurrent install operations
  3. Error scenario tests: Need tests for various failure modes in the new async flow

Impacted Features & Testing Recommendations

🎯 Critical Testing Areas

Primary Impact: VPN Configuration Installation

  • iOS: VPNPermissionViewController - Test permission grant/deny flows
  • tvOS: InstallVpnConfigurationProvider - Test installation error handling
  • Both platforms: Test force installation scenarios

Secondary Impact: Profile Management

  • Test profile switching during async operations
  • Verify database consistency during concurrent operations

📋 Recommended Test Scenarios

  1. Permission Flow Testing:

    ✓ Grant permission → successful installation
    ✓ Deny permission → proper error handling
    ✓ Multiple rapid permission requests → no race conditions
    ✓ Permission request during existing install → proper queuing
    
  2. Error Recovery Testing:

    ✓ Network failure during install → proper error propagation
    ✓ User logout during install → authorization error handling
    ✓ Profile conflict resolution → correct profile activation
    
  3. Threading Safety Testing:

    ✓ Concurrent install requests → proper serialization
    ✓ Install during profile switch → state consistency
    ✓ Background/foreground transitions → operation continuity
    

🔄 Integration Testing Priority

  1. High Priority: iOS permission flow end-to-end testing
  2. Medium Priority: tvOS async error handling validation
  3. Medium Priority: Profile migration scenarios during install
  4. Low Priority: Multiple protocol switching stress testing

Specific Recommendations

Immediate Actions Required:

  1. Fix infinite recursion in VPNPermissionViewController.swift:97 - replace recursive call with proper retry logic
  2. Add step-specific logging in DefaultVPNProvider.install() for debugging
  3. Add timeout handling for async operations that might hang

Technical Debt Items:

  1. Consider consolidating to async-only API in future versions
  2. Implement proper retry mechanism with exponential backoff
  3. Add telemetry for installation success/failure rates

The async migration is well-implemented overall, but needs the critical fix for potential infinite recursion and enhanced logging for debugging the original issue.


@kp-diego-trevisan
kp-diego-trevisan force-pushed the KM-13372-pia-fail-to-trigger-allow-vpn-permission branch from f9feb2f to 972f89a Compare March 10, 2026 10:15
@kp-diego-trevisan
kp-diego-trevisan deleted the KM-13372-pia-fail-to-trigger-allow-vpn-permission branch April 14, 2026 14:18
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.

1 participant