Skip to content

Commit

Permalink
Prevent sendProviderMessage calls when not necessary (#858)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1207603085593419/1207629954356116/f

iOS PR: duckduckgo/iOS#2979
macOS PR: duckduckgo/macos-browser#2892

What kind of version bump will this require?: Patch

## Description

The VPN toggle is sometimes failing silently, apparently due to a race condition created by calls to `sendProviderMessage` while the VPN is starting up.

This PR changes our logic to limit when those calls are made, since none of them make sense to call when the VPN is connecting.
  • Loading branch information
diegoreymendez authored Jun 21, 2024
1 parent 5362ffc commit 2806adf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public class ConnectionErrorObserverThroughSession: ConnectionErrorObserver {

private func handleStatusChangeNotification(_ notification: Notification) {
do {
guard let session = ConnectionSessionUtilities.session(from: notification) else {
guard let session = ConnectionSessionUtilities.session(from: notification),
session.status == .disconnected else {

return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public class ConnectionServerInfoObserverThroughSession: ConnectionServerInfoObs
// MARK: - Obtaining the NetP VPN status

private func updateServerInfo(session: NETunnelProviderSession) async {
guard session.status == .connected else {
return
}

let serverAddress = await self.serverAddress(from: session)
let serverLocation = await self.serverLocation(from: session)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public class DataVolumeObserverThroughSession: DataVolumeObserver {

private func updateDataVolume() {
Task {
guard let session = await tunnelSessionProvider.activeSession() else {
guard let session = await tunnelSessionProvider.activeSession(),
session.status == .connected else {

return
}

Expand Down

0 comments on commit 2806adf

Please sign in to comment.