Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Do not clear reasserting flag when connection is not recoverable #128

Merged
merged 3 commits into from
May 9, 2020

Conversation

rob-patchett
Copy link

@rob-patchett rob-patchett commented Oct 28, 2019

Issue I'm trying to solve

When attempting to connect, if there is an auth failure, the host application receives a connected status update from the extension before receiving a disconnected update, which leads to confusing UI changes and poor handling of the error state (in my case checking for an update in the user's VPN credentials).

What triggers the transient connected state

Setting NETunnelProvider's reasserting to false triggers a successful connection status from from OS.

Proposed solution

According to NEPacketTunnelProvider's docs, upon error, cancelTunnelWithError(_:) should be called: https://developer.apple.com/documentation/networkextension/nepackettunnelprovider/1406169-canceltunnelwitherror.
This PR proposes calling cancelTunnelWithError(_:) before reseting state in OpenVPNTunnelProvider.

This solution resolves the specific problem described above, but I'm not confident as to the lack of side effects. I'm also not sure the implications of calling cancelTunnelWithError(_:) from the error case in doReconnect. Any guidance or recommendations would be appreciated.

@keeshux keeshux self-assigned this Oct 30, 2019
@keeshux keeshux added the bug Something isn't working label Oct 30, 2019
@keeshux keeshux added this to the 2.1.1 milestone Oct 30, 2019
@keeshux keeshux removed this from the 2.1.1 milestone Nov 20, 2019
@keeshux keeshux added this to the 2.2.4 milestone May 3, 2020
@keeshux
Copy link
Member

keeshux commented May 3, 2020

Have you ever experienced #167? I'm wondering if it could also relate.

@rob-patchett
Copy link
Author

No I haven’t actually, so not really sure.

@keeshux
Copy link
Member

keeshux commented May 3, 2020

My concern is that cancelTunnelWithError IIRC kills the process, so:

  1. Calling it when shouldReconnect = true would be wrong.
  2. For non-error stops, it would still kill the process prematurely, as there's some stuff like pending log which wouldn't be finished up. Probably minor stuff but still I have to double check it.

I'm rather thinking of postponing reasserting with your considerations in mind. I'll let you know.

@rob-patchett
Copy link
Author

Gotcha. Sounds good, cheers.

jaroslavas referenced this pull request in ProtonVPN/ios-app May 6, 2020
@keeshux keeshux force-pushed the auth_failure branch 2 times, most recently from 0f3ee96 to add0583 Compare May 8, 2020 19:20
rob-patchett and others added 2 commits May 9, 2020 00:56
Both versions prevent clients from compiling, but this version
impacts less on existing codebase.
@keeshux
Copy link
Member

keeshux commented May 8, 2020

@rob-patchett I rebased to master as the former base was very outdated.

Have a look at my changes, I fixed the logic behind reconnection. It should make the abrupt cancelTunnelWithError: call unnecessary.

Use a different variable to signal an upcoming reconnection. Make
sure that reasserting is never set to false with the meaning of
"do not reconnect", because doing so would trigger a transient
"connected" state in the VPN.

Reverts use of cancelTunnelWithError() in sessionDidStop.
@keeshux keeshux changed the title Call cancelTunnelWithError(_:) if a connection fails and won't be retried Do not clear reasserting flag when connection is not recoverable May 8, 2020
@rob-patchett
Copy link
Author

@keeshux, yeah this looks good. I've retested and confirmed the problem is still resolved with these changes. Good to merge from my side 👍

Thanks for improving!

@keeshux keeshux merged commit 9b82d7f into passepartoutvpn:master May 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants