Fix #68: Traffic statistics freeze after app process restart - #71
Open
aimkiray wants to merge 1 commit into
Open
Fix #68: Traffic statistics freeze after app process restart#71aimkiray wants to merge 1 commit into
aimkiray wants to merge 1 commit into
Conversation
Two independent bugs caused traffic stats to freeze when the :vpn or app process restarted: 1. BaseService.Binder used a plain RemoteCallbackList for callbacks but a separate bandwidthListeners map that was never cleaned up when a callback binder died. After an app-process restart, the stale entry kept the 1 Hz traffic looper running for nobody, and startListeningForBandwidth only added a listener when the map was empty — so the new binder was silently skipped. Override onCallbackDied to remove the dead entry and cancel the looper when empty; always (re)register the listener. 2. MeowConnection never rebound after onServiceDisconnected. When the :vpn process was killed (OOM, crash), the connection was lost but never re-established. Remember the binding context; rebind in onServiceDisconnected. @synchronized on connect/disconnect/ onServiceDisconnected prevents concurrent access; disconnect() clears bindContext first so a racing rebind is a no-op after a clean unbind. Fixes meow-rs#68
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #68
Supersedes closed PR #67, which was incompatible with
mainafter the Compose migration (#63) and mihomo→meow rename (#57).Problem
When the app process is killed by the system (memory pressure) while the
:vpnprocess stays alive, traffic statistics freeze permanently. After restarting the app, the traffic chart and speed display stop updating and never recover until the VPN is manually stopped and reconnected.Root cause
BaseService.Bindermaintains two parallel data structures for bandwidth listeners:RemoteCallbackListautomatically removes dead binders when a callback's process dies. However, the plainMutableMapdoes not — andonCallbackDiedwas not overridden to mirror the cleanup. After the app process is killed and restarted:bandwidthListenersstartListeningForBandwidthguards onisEmpty():isEmpty() == false(stale entry) →put()is never called → new listener is never registeredloop(),bandwidthListeners.contains(newBinder)returnsfalse→trafficUpdatedis never called for the new callbackFix
BaseService.Binder:RemoteCallbackList.onCallbackDiedto remove the dead binder frombandwidthListenersand cancel the looper when emptyisEmpty()guard instartListeningForBandwidth; always register the listener (bandwidthListeners[cb.asBinder()] = timeout); start the looper only if not already activeMeowConnection(defensive improvements):boundflag andbindContextto support rebindingonServiceDisconnectedviaBIND_AUTO_CREATEsoservicereference is restored sooner after:vpndeath@Synchronizedonconnect()/disconnect()/onServiceDisconnected()for thread safetyboundflag prevents double-unbindServicecrashTesting
Device-tested on physical Android 16 (SDK 36):
am killkills app,:vpnsurvives (same PID 17871):vpnPID unchanged (17871) throughoutThe previous PR #67 tested the wrong scenario (killing
:vpninstead of the app process). This PR tests the actual bug trigger: killing the app process while:vpnsurvives.Files changed
core/.../bg/BaseService.kt—onCallbackDiedoverride + unconditional listener registrationcore/.../aidl/MeowConnection.kt— rebind +@Synchronized+boundflag