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

When computer enters sleep mode, Brave's VPN status is out of sync with the OS #29500

Closed
bsclifton opened this issue Apr 4, 2023 · 5 comments · Fixed by brave/brave-core#22541

Comments

@bsclifton
Copy link
Member

bsclifton commented Apr 4, 2023

Description

VPN status is out of sync after sleep

Thanks to @iambrianfung for reporting

Steps to Reproduce

  1. Have VPN purchased and working
  2. Connect to VPN inside Brave and leave open
  3. Put computer to sleep
  4. Wake computer from sleep
  5. Look at VPN button in Brave
  6. Look at VPN panel's state in Brave

Actual result:

Button's state is disconnected
Panel's state is in-progress

Expected result:

Button's state is disconnected
Panel's state is disconnected

Brave version (brave://version info)

MacOS 1.49.132 Chromium: 111.0.5563.147 (Official Build) (arm64)

NOTE: Initially this issue reports inconsistency between os vpn status and toolbar vpn button.
It's fixed already but found that panel status has similar issue and only happens on macOS.

@bsclifton
Copy link
Member Author

This might not be an issue anymore...
cc: @simonhong

@simonhong simonhong self-assigned this Mar 11, 2024
@simonhong
Copy link
Member

Not sure this doesn't happen now.
AFAIK, we don't check connection state again after wakeup. will check soon.

@simonhong
Copy link
Member

On macOS laptop, I can't see this issue. os vpn is disconnected and vpn toolbar button also has disconnected state after wakeup.
However, I could see another similar situation.
After wakeup, vpn panel shows in-progress loading after wakeup.
Captured related logs. it explains well what happened.

====After wake up

[3188:259:0311/201559.645942:VERBOSE2:ikev2_connection_api_impl_mac.mm(349)] Received VPN connection status change notification
[3188:259:0311/201559.646256:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusReasserting
[3188:259:0311/201559.646291:VERBOSE2:system_vpn_connection_api_impl_base.cc(195)] OnIsConnecting
[3188:259:0311/201559.646320:VERBOSE2:system_vpn_connection_api_impl_base.cc(285)] UpdateAndNotifyConnectionStateChange : changing from CONNECTED to CONNECTING
[3188:259:0311/201559.646345:VERBOSE2:brave_vpn_service.cc(132)] OnConnectionStateChanged CONNECTING
[3188:259:0311/201600.155690:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusReasserting
[3188:259:0311/201600.155755:VERBOSE2:system_vpn_connection_api_impl_base.cc(195)] OnIsConnecting
[3188:259:0311/201600.155860:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusReasserting
[3188:259:0311/201600.155887:VERBOSE2:system_vpn_connection_api_impl_base.cc(195)] OnIsConnecting
[3188:259:0311/201600.849938:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusReasserting
[3188:259:0311/201600.849973:VERBOSE2:system_vpn_connection_api_impl_base.cc(195)] OnIsConnecting
[3195:20995:0311/201601.696991:WARNING:dns_config_service_posix.cc(196)] Failed to read DnsConfig.
[3188:25607:0311/201601.697257:WARNING:dns_config_service_posix.cc(196)] Failed to read DnsConfig.
[3195:20995:0311/201603.009815:WARNING:dns_config_service_posix.cc(196)] Failed to read DnsConfig.
[3188:25607:0311/201603.009912:WARNING:dns_config_service_posix.cc(196)] Failed to read DnsConfig.
[3188:259:0311/201603.672765:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusReasserting
[3188:259:0311/201603.672824:VERBOSE2:system_vpn_connection_api_impl_base.cc(195)] OnIsConnecting
[3188:259:0311/201603.672916:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusReasserting
[3188:259:0311/201603.672938:VERBOSE2:system_vpn_connection_api_impl_base.cc(195)] OnIsConnecting
[3188:25607:0311/201614.914977:ERROR:trust_store_mac.cc(750)] Error parsing certificate:
ERROR: Failed parsing extensions

[3188:259:0311/201615.706857:VERBOSE2:ikev2_connection_api_impl_mac.mm(349)] Received VPN connection status change notification
[3188:259:0311/201615.707135:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusDisconnected
[3188:259:0311/201615.707169:VERBOSE2:system_vpn_connection_api_impl_base.cc(273)] UpdateAndNotifyConnectionStateChange: Ignore disconnected state while connecting
[3188:259:0311/201616.209104:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusDisconnected
[3188:259:0311/201616.209147:VERBOSE2:system_vpn_connection_api_impl_base.cc(273)] UpdateAndNotifyConnectionStateChange: Ignore disconnected state while connecting
[3188:259:0311/201616.209211:VERBOSE2:ikev2_connection_api_impl_mac.mm(321)] CheckConnection: NEVPNStatusDisconnected
[3188:259:0311/201616.209229:VERBOSE2:system_vpn_connection_api_impl_base.cc(273)] UpdateAndNotifyConnectionStateChange: Ignore disconnected state while connecting

After wakeup, browser receives NEVPNStatusReasserting event notification.
According to the docs, maybe macOS tried to reconnect.
and we translate it as connection in-progress because that status means os is trying to reconnect.

    NEVPNStatus current_status = [[vpn_manager connection] status];
    VLOG(2) << "CheckConnection: " << NEVPNStatusToString(current_status);
    switch (current_status) {
      case NEVPNStatusConnected:
        OnConnected();
        break;
      case NEVPNStatusConnecting:
      case NEVPNStatusReasserting:
        OnIsConnecting();
        break;
      case NEVPNStatusDisconnected:
      case NEVPNStatusInvalid:
        OnDisconnected();
        break;
      case NEVPNStatusDisconnecting:
        OnIsDisconnecting();
        break;
      default:
        break;
    }

After that, browser receives CheckConnection: NEVPNStatusDisconnected because on-demand is off.
However, this disconnected notification is ignored by our state handling logic.
Due to that, we're stuck in in-progress state after wakeup.

  // Ignore disconnected state while connecting is in-progress.
  // Network status can be changed during the vpn connection because
  // establishing vpn connection could make system network offline temporarily.
  // Whenever we get network status change, we check vpn connection state and
  // it could give disconnected vpn connection during that situation.
  // So, don't notify this disconnected state change while connecting because
  // it's temporal state.
  if (GetConnectionState() == ConnectionState::CONNECTING &&
      state == ConnectionState::DISCONNECTED && !cancel_connecting_) {
    VLOG(2) << __func__ << ": Ignore disconnected state while connecting";
    return;
  }

IMO, we don't need to handle NEVPNStatusReasserting.
Just ignoring that noti will fix this issue. Maybe this event happens from macOS not by user's interaction.
After that state is gone, macOS will give connected or disconnected. So, we could update vpn state properly with that last event. I'll test with it.

@stephendonner
Copy link

stephendonner commented Apr 2, 2024

Verification PASSED using

Brave	1.66.53 Chromium: 123.0.6312.86 (Official Build) nightly (x86_64) 
Revision	a79fb87f4f3b5b0c833644ed870a657eef74b987
OS	macOS Version 11.7.10 (Build 20G1427)

Steps:

  1. installed 1.66.53
  2. launched Brave
  3. loaded account.bravesoftware.com
  4. purchased, configured, and connected to Brave VPN
  5. clicked on Apple menu -> Sleep
  6. awoke computer from sleep
  7. examined VPN button
  8. examined VPN panel

Confirmed I was connected to Brave VPN via several methods (panel, VPN button, menu-item entry)

before Sleep, connected after Sleep, connected (button + menu item) after Sleep, connected (panel)
Screen Shot 2024-04-02 at 4 00 56 PM Screen Shot 2024-04-02 at 4 02 26 PM Screen Shot 2024-04-02 at 4 04 43 PM

@stephendonner
Copy link

Verified PASSED using

Brave	1.66.53 Chromium: 123.0.6312.86 (Official Build) nightly (arm64) 
Revision	a79fb87f4f3b5b0c833644ed870a657eef74b987
OS	macOS Version 13.6.4 (Build 22G513)

Steps:

  1. installed 1.66.53
  2. launched Brave
  3. loaded account.bravesoftware.com
  4. purchased, configured, and connected to Brave VPN
  5. clicked on Apple menu -> Sleep
  6. awoke computer from sleep
  7. examined VPN button
  8. examined VPN panel

Confirmed I was connected to Brave VPN via several methods (panel, VPN button, menu-item entry)

before Sleep, connected after Sleep, connected (button + menu item) after Sleep, connected (panel)
Screenshot 2024-04-02 at 4 16 56 PM Screenshot 2024-04-02 at 4 17 39 PM Screenshot 2024-04-02 at 4 19 47 PM

@rebron rebron changed the title After computer went to sleep, Brave's VPN status is out of sync with the OS When computer enters sleep mode, Brave's VPN status is out of sync with the OS Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment