Skip to content

Commit

Permalink
Add a 2 second delay before shutting down the tunnel when encounterin…
Browse files Browse the repository at this point in the history
…g an error (#1078)

Required:

Task/Issue URL: https://app.asana.com/0/1207603085593419/1208772807738114/f
iOS PR: duckduckgo/iOS#3579
macOS PR: duckduckgo/macos-browser#3557
What kind of version bump will this require?: Patch

Description:

This PR adds a short delay when shutting down the tunnel.
  • Loading branch information
samsymons authored Nov 22, 2024
1 parent b18e710 commit deacf61
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/NetworkProtection/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
// expired. In either case it should be enough to record the manual failures
// for these prerequisited to avoid flooding our metrics.
providerEvents.fire(.tunnelStartOnDemandWithoutAccessToken)
try await Task.sleep(interval: .seconds(15))
try? await Task.sleep(interval: .seconds(15))
} else {
// If the VPN was started manually without the basic prerequisites we always
// want to know as this should not be possible.
Expand All @@ -704,9 +704,13 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {

// Check that the error is valid and able to be re-thrown to the OS before shutting the tunnel down
if let wrappedError = wrapped(error: error) {
// Wait for the provider to complete its pixel request.
providerEvents.fire(.malformedErrorDetected(error))
try? await Task.sleep(interval: .seconds(2))
throw wrappedError
} else {
// Wait for the provider to complete its pixel request.
try? await Task.sleep(interval: .seconds(2))
throw error
}
}
Expand All @@ -725,7 +729,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
// We add a delay when the VPN is started by
// on-demand and there's an error, to avoid frenetic ON/OFF
// cycling.
try await Task.sleep(interval: .seconds(15))
try? await Task.sleep(interval: .seconds(15))
}

let errorDescription = (error as? LocalizedError)?.localizedDescription ?? String(describing: error)
Expand All @@ -738,9 +742,13 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {

// Check that the error is valid and able to be re-thrown to the OS before shutting the tunnel down
if let wrappedError = wrapped(error: error) {
// Wait for the provider to complete its pixel request.
providerEvents.fire(.malformedErrorDetected(error))
try? await Task.sleep(interval: .seconds(2))
throw wrappedError
} else {
// Wait for the provider to complete its pixel request.
try? await Task.sleep(interval: .seconds(2))
throw error
}
}
Expand Down

0 comments on commit deacf61

Please sign in to comment.