Keep the network listener active after callback fallback - #141
Conversation
📝 WalkthroughWalkthroughThe change adds a stateful ChangesNetwork callback lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
ef30d16 to
dd6323a
Compare
dd6323a to
c391f99
Compare
c391f99 to
d1b50a1
Compare
d1b50a1 to
5ff2347
Compare
| fallback = true | ||
| return |
There was a problem hiding this comment.
Fallback Still Stalls When unregister cleanup keeps failing, this branch returns before installing a new Android network callback. The next
Start only receives the current activeNetwork, so later Wi-Fi/mobile switches or network loss are not delivered through onAvailable or onLost. After a service restart in this state, underlyingNetwork can stay stale for the rest of the process unless the old callback is still active.
There was a problem hiding this comment.
No change. After repeated platform cleanup failures, callback ownership is unknown. Registering again could create duplicate callbacks and conflicting stale events. The listener retries cleanup on each restart, delivers the current active network while uncertain, and keeps the actor alive; conservative fallback is the safe residual behavior.
There was a problem hiding this comment.
Fair point — when unregister fails, the old callback's ownership is genuinely ambiguous, and a blind re-register in that state could produce duplicates or conflicting onAvailable/onLost events that are harder to reason about than a known-stale snapshot. The retry-on-restart + current-network delivery is a coherent conservative contract.
Withdrawing the concern. The fallback behavior is intentional and the reasoning is sound.
|
Latest commit passed Namespace CI run 29213429522. |
Summary
Validation
Greptile Summary
This PR keeps the network listener usable when callback unregister or register calls fail. The main changes are:
Confidence Score: 4/5
This is close, but the fallback recovery path should be fixed before merging.
app/src/main/java/io/nekohasekai/sagernet/utils/DefaultNetworkListener.kt
Important Files Changed
Reviews (5): Last reviewed commit: "fix(network): preserve listener after fa..." | Re-trigger Greptile