Skip to content

Improve connectivity detection and proxy handling#14764

Open
valldrac wants to merge 5 commits into
signalapp:mainfrom
valldrac:networklistener-refactor
Open

Improve connectivity detection and proxy handling#14764
valldrac wants to merge 5 commits into
signalapp:mainfrom
valldrac:networklistener-refactor

Conversation

@valldrac
Copy link
Copy Markdown
Contributor

@valldrac valldrac commented May 9, 2026

This PR is an attempt to address #14528.

The main goal is to make Internet connectivity detection more reliable under VPNs and fast network transitions, as discussed in the linked issue.

The core change is a new InternetConnectivityMonitor, which replaces NetworkConnectionListener. The new monitor tracks all active networks, including VPNs, and derives a single connectivity state from that aggregate view. This is intended to fix cases where IncomingMessageObserver can make the wrong connection decision under always-on VPNs and kill switch.

Also, the previous code was mixing asynchronous connectivity updates from NetworkCallback with synchronous connectivity checks via deprecated APIs. Our assumption is that this could lead to races and inconsistent connection decisions when networks switches quickly.

Proxy handling is also reworked. Proxy change events are now detected via PROXY_CHANGE_ACTION system broadcast. We removed the old proxy lookup path and its IPC overhead from SignalServiceNetworkAccess. Proxy resolution now uses ProxySelector, which handles PAC and exclusion rules transparently.

Summary of changes:

  • Replace NetworkConnectionListener with InternetConnectivityMonitor
  • Handle VPN and blocked networks more explicitly
  • Switch proxy detection to ProxySelector
  • Move proxy config state into a separate object owned by the network module
  • Avoid restaring the complete network module on proxy changes
  • Fix a semaphore lost-wakeup race in waitForConnectionNecessary()
  • Remove a now-redundant explicit lock in IncomingMessageObserver

A few notes:

  • This approach has been running in production in Molly (on API 27+) without issues so far.
  • The monitor could be moved to AppDependencies and extended to deprecate NetworkUtil.java.
  • The proxy changes are newer and have less battle test, so extra review there is welcome.

We split the work into smaller commits so each one can be reviewed independently, but ideally in order.

Closes #14528.

valldrac and others added 5 commits May 9, 2026 18:17
Replace NetworkConnectionListener with InternetConnectivityMonitor,
which uses a coroutine-based Flow to aggregate per-network state and
derive a single ConnectivityState. The monitor tracks all networks
instead of relying on the default network callback, so VPN and
underlying networks are considered.

Co-authored-by: S1m <31284753+p1gp1g@users.noreply.github.com>
The ProxySelector approach is simpler and handles PAC transparently.

On proxy change detection in IncomingMessageObserver, reconfigure the
libsignal network proxy and reconnect the websockets, instead of
resetting the entire network module.
It eliminates the race where an initial drainPermits() in the wait loop
could silently discard a valid wake-up signal.
Following the previous refactor, the ReentrantLock is no longer needed.

The only remaining shared state is appVisible and lastInteractionTime,
which are replaced with an AppState data class to keep reads consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connectivity detection issues under VPN and network loss

1 participant