fix(core): remove once listeners by identity, not stale index - #11306
Merged
NathanWalker merged 1 commit intoJul 17, 2026
Merged
Conversation
Observable._fireEvent iterates a copy of the observers array but passed the copy's loop index to _handleListenerEntry, which spliced the live array at that position. When an earlier listener was removed during the same notify pass (a handler calling off() on itself, or a preceding `once` entry being consumed), the live array shifted left and the splice for a later `once` entry removed the wrong listener or none at all. The `once` listener then stayed subscribed and fired on every subsequent notify, while an unrelated listener could be silently unsubscribed. Look up the entry's current position via indexOf before splicing and mark it _isRemoved (matching innerRemoveEventListener), so a consumed `once` entry is removed exactly once - still before its callback runs - even when the array has shifted or the notify pass re-enters.
Contributor
|
@jkatins Nice finding and explanation! |
CatchABus
approved these changes
Jul 16, 2026
|
View your CI Pipeline Execution ↗ for commit 9454b71
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
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.
PR Checklist
What is the current behavior?
Regression introduced in 1e55f0c (#10946), first released in core 9.0.0.
Observable._fireEventiterates a copy of the observers array but passes the copy's loop index to_handleListenerEntry, which splices the live array at that position. If any listener at a lower index is removed during the same notify pass (a handler callingoff()on itself, or a precedingonceentry being consumed), the live array shifts left and the splice for a lateronceentry removes the wrong element or nothing at all. Consequences:oncelistener stays subscribed and fires on every subsequent notify.The
launchevent is affected deterministically in every app:NativeScriptGlobalStateregisters_setLaunchedas the first launch listener and it removes itself inside its handler, so everyApplication.once('launch', ...)remains permanently armed. On Android this crashes apps that bootstrap from a launch listener and keep their process alive with a foreground service: recreating the activity (e.g. back-button exit, then relaunch) fireslaunchagain, the armedonceruns the bootstrap a second time andApplication.run()throwsError: Application is already started.insideNativeScriptActivity.onCreate.Minimal repro: