Fix: Multitouch stability during rapid system changes#96
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR addresses a critical crash (MIDDLEDRAG-G) caused by race conditions in the MultitouchSupport framework during rapid connectivity changes. The fix employs a defense-in-depth strategy combining increased timing delays and explicit locking to prevent the framework's internal thread from accessing deallocated device references during cleanup.
Changes:
- Increased framework cleanup delays from 100-250ms to 500ms to allow proper resource cleanup during rapid connectivity toggling
- Increased minimum restart interval from 300ms to 600ms to better debounce rapid restart triggers
- Added
os_unfair_lockprotection aroundMTDeviceStopcalls to prevent concurrent access during critical shutdown operations
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| MiddleDrag/Managers/MultitouchManager.swift | Updated timing constants (restartCleanupDelay and minimumRestartInterval) with improved documentation explaining the rationale for rapid connectivity change scenarios |
| MiddleDrag/Managers/DeviceMonitor.swift | Increased frameworkCleanupDelay and added lock protection around MTDeviceStop calls to prevent concurrent framework access during device shutdown |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Increased from 50ms to handle rapid foreground/background toggling scenarios. | ||
| static let frameworkCleanupDelay: TimeInterval = 0.1 | ||
| /// Value determined empirically: 500ms is sufficient to avoid CFRelease(NULL) crashes | ||
| /// and EXC_BREAKPOINT exceptions during rapid connectivity changes (wifi ↔ none). |
There was a problem hiding this comment.
The term "wifi" should be capitalized as "Wi-Fi" for proper spelling.
| /// and EXC_BREAKPOINT exceptions during rapid connectivity changes (wifi ↔ none). | |
| /// and EXC_BREAKPOINT exceptions during rapid connectivity changes (Wi-Fi ↔ none). |
| /// handle rapid foreground/background toggling that can trigger multiple restart cycles. | ||
| static let restartCleanupDelay: TimeInterval = 0.25 | ||
| /// Value determined empirically: 500ms is sufficient to avoid CFRelease(NULL) crashes | ||
| /// and EXC_BREAKPOINT exceptions during rapid connectivity changes (wifi ↔ none). |
There was a problem hiding this comment.
The term "wifi" should be capitalized as "Wi-Fi" for proper spelling.
| /// by waiting at least this long after the last restart completed. | ||
| static let minimumRestartInterval: TimeInterval = 0.3 | ||
| /// When multiple restart triggers occur in rapid succession (e.g., rapid connectivity | ||
| /// changes wifi ↔ none), we debounce them by waiting at least this long after the |
There was a problem hiding this comment.
The term "wifi" should be capitalized as "Wi-Fi" for proper spelling.
Description
Fixes MIDDLEDRAG-G. The issue was that: Rapid connectivity changes triggered overlapping multitouch device restarts, causing the MultitouchSupport framework's internal thread to
CFReleasea deallocated device reference.frameworkCleanupDelayandrestartCleanupDelayto 0.5s to prevent crashes during rapid connectivity changes and restart cycles.os_unfair_lockaroundMTDeviceStopcalls to preventCFRelease(NULL)crashes from concurrent access.minimumRestartIntervalto 0.6s to debounce rapid restart triggers and mitigate race conditions.Type of Change
Related Issues
Fixes MIDDLEDRAG-G
Testing Performed
[ ] Tested in target apps (list any specific apps tested):
Checklist
Code Coverage
Screenshots / Recordings
Additional Notes
This fix was generated by Seer in Sentry, triggered by Karan Mohindroo. 👁️ Run ID: 9814512
Not quite right? Click here to continue debugging with Seer.