fix: remove deadlock in pt_usleep sleep-spam blocker (can hang render thread → os_unfair_lock crash) - #234
Open
ap-harsa-yamani wants to merge 1 commit into
Conversation
The sleep-spam blocker locked an NSLock inside dispatch_once and never unlocked it, then tried to lock it again when a thread exceeded the usleep limit. NSLock is not recursive, so the second lock deadlocks the thread forever instead of stopping it. If the hung thread is a render/GPU thread (UnityGfxDeviceWorker) or the main thread, this corrupts os_unfair_lock and crashes the game (observed in Arknights: Endfield). Replace the deadlocking lock with a simple return 0 (skip the sleep), which stops the spam without hanging the thread. Remove the now-unneeded UIApplicationWillTerminateNotification unlock observer.
Member
|
@ohaiibuzzle not sure what the original design intention was for the lock system was |
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
Fixes a deadlock in the
pt_usleepsleep-spam blocker (blockSleepSpammingtoggle) that can hang a thread forever — and, when the hung thread is a render/GPU thread, corruptsos_unfair_lockand crashes the game.The bug
In
PlayTools/PlayLoader.m,pt_usleep:NSLockis not recursive: the lock taken insidedispatch_once(1) is held forever, so the secondlock(2) blocks the thread permanently instead of "stopping" it.UnityGfxDeviceWorker/ a render thread / the main thread, the render pipeline hangs →os_unfair_lockcorruption → crash.BUG IN CLIENT OF LIBPLATFORM: Trying to recursively lock an os_unfair_lock,EXC_BREAKPOINT/SIGKILL), see [Game Support]: Arknights: Endfield GPU-related thread lock corruption causes crash PlayCover#2067 and [Bug]: Arknights Endfield 1.4.3 silent-exits after ~60s on M3/8GB macOS 26.6.1 — no crash report, all bypasses exhausted PlayCover#2202.The fix
thread_sleep_lockentirely. The per-thread counter is already protected by@synchronized(thread_sleep_counters).return 0) instead of hanging it — same anti-spam effect, no deadlock.UIApplicationWillTerminateNotificationobserver that unlocked the (now removed) lock.Testing
xcodebuildhere (no iOS SDK toolchain available in this environment); the diff is minimal and self-contained.blockSleepSpammingin a Unity game (e.g. Endfield), and confirm the game no longer hangs/crashes after ~60s.Related