Fix crash: ThreadGuardedValue accessed after destroy in RunLoop race#2012
Open
hezhizhen wants to merge 1 commit intonikitabobko:mainfrom
Open
Fix crash: ThreadGuardedValue accessed after destroy in RunLoop race#2012hezhizhen wants to merge 1 commit intonikitabobko:mainfrom
hezhizhen wants to merge 1 commit intonikitabobko:mainfrom
Conversation
When an app is destroyed, `CFRunLoopStop` is asynchronous — pending AX notification callbacks can still fire and access `windows`/`axApp` after `destroy()` has already set `_threadGuarded` to nil, causing a crash with "Value is already destroyed". Add `threadGuardedOrNil` safe accessor to `ThreadGuardedValue` that returns nil instead of crashing, and use it in all RunLoop closures in `MacApp` so they gracefully bail out post-destroy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@nikitabobko I know little about Swift, so I let claude code read the source code and error log and it created such a PR. Please check if it fixes the crash if it's okay for you to review an AI-automated PR. |
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.
When an app is destroyed,
CFRunLoopStopis asynchronous — pending AX notification callbacks can still fire and accesswindows/axAppafterdestroy()has already set_threadGuardedto nil, causing a crash with "Value is already destroyed".Add
threadGuardedOrNilsafe accessor toThreadGuardedValuethat returns nil instead of crashing, and use it in all RunLoop closures inMacAppso they gracefully bail out post-destroy.Try to fix #1921
PR checklist
./run-tests.shexits with non-zero exit code.Failure to follow the checklist with no apparent reasons will result in silent PR rejection.