Fix PAGImageView deadlock when size updates trigger flush#3348
Fix PAGImageView deadlock when size updates trigger flush#3348Batxent wants to merge 3 commits intoTencent:mainfrom
Conversation
…etFrame to prevent potential deadlocks
…event re-entrancy deadlocks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3348 +/- ##
==========================================
- Coverage 75.60% 75.59% -0.01%
==========================================
Files 510 510
Lines 35435 35435
Branches 11283 11283
==========================================
- Hits 26789 26786 -3
+ Misses 6356 6355 -1
- Partials 2290 2294 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The main issue here is lock re-entrancy.
So the effective path was:
Because the mutex is non-recursive, this can deadlock on the same thread. The fix is to keep the decoder reset under the lock, but defer |
Summary
PAGImageViewanimator updates out of theimageViewLockscope insetBounds:andsetFrame:update -> onAnimationFlush -> flush()from re-entering the same non-recursive mutexRoot Cause
PAGImageViewused to call[animator update]while still holdingimageViewLockduring size changes.That update path can synchronously flow through:
update -> onAnimationFlush -> flush()flush()also acquiresimageViewLock, so the same thread can try to lock the same non-recursive mutex twice and deadlock.Fix
Keep decoder reset and size-related state updates inside
imageViewLock, but defer[animator update]until after the lock has been released.This preserves the existing flush behavior while removing the re-entrant lock path.
Validation
PAGImageViewhandled size changes and an immediate flush was triggeredlibpagforiphoneoswith the patch