Skip to content

Refactor NetworkCallback listener to correctly track connectivity under VPN#673

Merged
valldrac merged 2 commits intomainfrom
networklistener-refactor
Feb 6, 2026
Merged

Refactor NetworkCallback listener to correctly track connectivity under VPN#673
valldrac merged 2 commits intomainfrom
networklistener-refactor

Conversation

@valldrac
Copy link
Member

@valldrac valldrac commented Jan 11, 2026

Previously, the listener could incorrectly report Internet access as available when it wasn't, or unavailable when it actually was.

Changes:

  • Remove NET_CAPABILITY_NOT_VPN to correctly track VPN networks.
  • Track connectivity via a restartable coroutine Flow.
  • Handle VPN state transitions when kill-switch is enabled.
  • Force connection attempt on push notification, regardless of reported network state.

We already track all networks individually rather than using a single state, unlike upstream (2dae3cc, 7859ca3).

Fixes #352, fixes #663

Copy link
Member

@p1gp1g p1gp1g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've commented a few things to improve the kotlin flows.

One of the most important comment is about onLost.

But the problem exists even if you always close the coroutine onLost. That's because Molly may start when the VPN is considered connected but the device doesn't have any transport network available: we get networks = (123 to NetworkState(validated = true, blocked = false, onVpn = true)) and conclude isOnline = true

EDIT: in this case bestNetworkState changed validated to false => that's OK, unless there is another weird bug

@valldrac valldrac force-pushed the networklistener-refactor branch from 34580d3 to e62cbd6 Compare January 12, 2026 15:51
@p1gp1g
Copy link
Member

p1gp1g commented Jan 12, 2026

There is a repetitive check, else, it looks good to me

@valldrac valldrac marked this pull request as ready for review January 12, 2026 17:13
@valldrac valldrac force-pushed the networklistener-refactor branch 2 times, most recently from e556ba0 to b97f16d Compare January 13, 2026 12:56
@valldrac
Copy link
Member Author

Fixed the unnecessary check. Also renamed the class to InternetConnectivityMonitor, it better describes its purpose and avoids merge conflicts with upstream.

@valldrac valldrac changed the title Refactor NetworkConnectionListener to correctly track Internet connectivity under VPN Refactor NetworkCallback listener to correctly track connectivity under VPN Jan 13, 2026
valldrac and others added 2 commits February 6, 2026 10:01
@valldrac valldrac force-pushed the networklistener-refactor branch from b97f16d to b91e992 Compare February 6, 2026 09:07
@valldrac valldrac merged commit 2241276 into main Feb 6, 2026
2 checks passed
@valldrac valldrac deleted the networklistener-refactor branch February 6, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Delayed notifications using FCM and Mullvad VPN enabled. Molly: Messages does not get sent because of VPN

2 participants