Skip to content

fix: synchronize sleep-spam tracking state - #230

Merged
JoseMoreville merged 1 commit into
PlayCover:masterfrom
hedssaz:fix/thread-safe-sleep-spam-tracking
Aug 12, 2026
Merged

fix: synchronize sleep-spam tracking state#230
JoseMoreville merged 1 commit into
PlayCover:masterfrom
hedssaz:fix/thread-safe-sleep-spam-tracking

Conversation

@hedssaz

@hedssaz hedssaz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • synchronize access to the shared sleep-spam tracking dictionaries
  • keep the counter update and threshold check in the same critical section

Root cause

pt_usleep can run concurrently on multiple game threads while blockSleepSpamming is enabled. The shared NSMutableDictionary instances were read and mutated without synchronization. Concurrent access could corrupt their internal storage during insertion or rehashing and crash the game from pt_usleep.

Impact

This preserves the existing sleep-spam detection behavior while preventing dictionary access races during game startup and runtime.

Testing

  • built the PlayTools Release scheme for a generic iOS device with code signing disabled
  • verified the synchronization fix in Arknights: Endfield on macOS 26 with sleep-spam blocking enabled

@hedssaz

hedssaz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Stress-tested the synchronized tracking path with 256 concurrent pthreads over 20 rounds (517,120 calls), plus a Thread Sanitizer run with 64 threads over 10 rounds (64,640 calls): no crashes or data races were reported, and every thread remained below the threshold for calls 1–100 and crossed it exactly on call 101.

@TheMoonThatRises TheMoonThatRises added the enhancement New feature or request label Aug 12, 2026
@JoseMoreville
JoseMoreville merged commit d44d418 into PlayCover:master Aug 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants