Fix: terminal freezes when activity is destroyed while new instance already bound#5094
Open
Frodotus wants to merge 1 commit into
Open
Fix: terminal freezes when activity is destroyed while new instance already bound#5094Frodotus wants to merge 1 commit into
Frodotus wants to merge 1 commit into
Conversation
…lready bound When the activity is recreated (e.g. on theme reload or home-launcher restart after Exit), the new TermuxActivity can bind to the service and call setTermuxTerminalSessionClient() before the old activity's onDestroy() runs. The old onDestroy() then calls unsetTermuxTerminalSessionClient() unconditionally, replacing the new activity's session client with the no-op service client. This causes onTextChanged() to stop triggering terminal redraws, freezing the terminal until the app is force-stopped. Fix by passing the calling activity's own client to a new guarded overload of unsetTermuxTerminalSessionClient() that skips the unset if another activity has already taken over the client slot.
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
When the activity is recreated — either after
recreate()(e.g. theme/style reload) or when Termux is used as a home launcher and a new instance starts after Exit — the newTermuxActivitycan bind to the service and callsetTermuxTerminalSessionClient()before the old activity'sonDestroy()runs.The old
onDestroy()then callsunsetTermuxTerminalSessionClient()unconditionally, replacing the new activity's session client with the no-opTermuxTerminalSessionServiceClient. This causesonTextChanged()to stop triggering terminal redraws — the terminal appears completely frozen until the app is force-stopped.Root cause
TermuxActivity.onDestroy():Android's lifecycle guarantees the new instance reaches
onResume()before the old one'sonDestroy()fires.onServiceConnected()(which callssetTermuxTerminalSessionClient()) is delivered on the main thread shortly afterbindService()inonCreate(), so it reliably arrives beforeonDestroy()of the outgoing activity.Fix
Add a guarded overload
unsetTermuxTerminalSessionClient(client)that only unsets if the stored client still matches the caller. Use it fromonDestroy()instead of the unconditional version.Reproduction
Reliable: configure Termux as a home launcher, tap "Exit" in the notification. The restarted terminal will be completely frozen (no output rendered). Toggling the soft keyboard or extra-keys bar forces a single redraw but the freeze persists until force-stop.
The same race occurs on any theme-reload that calls
recreate().