Fix delayed state updates when stopping Clash services - #398
Merged
Conversation
Goooler
force-pushed
the
fix-lagging-for-switch
branch
from
August 25, 2026 11:08
a3536c4 to
1a5fadc
Compare
Goooler
force-pushed
the
fix-lagging-for-switch
branch
from
August 25, 2026 11:19
1a5fadc to
99ae443
Compare
Goooler
force-pushed
the
fix-lagging-for-switch
branch
from
August 25, 2026 11:26
d29a85f to
2a284ec
Compare
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.
Overview
Fixes an issue where stopping Clash from the Home screen, Quick Settings tile, or external shortcuts can leave the app reporting a running or transitioning state for several seconds on some devices, including Motorola and Lenovo devices using aggressive background process management. The delayed stopped state also keeps settings that depend on
clashRunningtemporarily unavailable.Root cause
The runtime had already closed the TUN interface and reset Clash, but the app did not clear
StatusProvider.serviceRunningor broadcastACTION_CLASH_STOPPEDuntil Android invokedService.onDestroy().On the affected device, runtime cleanup completed in about 20 ms while
onDestroy()arrived about 6.6 seconds afterstopSelf(). Consumers therefore reflected Android service teardown latency rather than the actual Clash state.Changes
ClashServiceControllerto share lifecycle, status, notification, and broadcast handling betweenTunServiceandClashService.onStartCommand()so an existing service instance can handle a new start request.stopSelf(startId)during shutdown.ACTION_CLASH_STOPPEDso state consumers update immediately;onDestroy()handling as a fallback for service termination outside the normal runtime completion path.Validation
onDestroy()callback.