Closed irobbin1024 closed 6 years ago
非常感谢如此详细的分析~~~
已发布 1.1.3 修复此问题。Pod 更新即可。
我这没复现环境,如有问题可继续与我联系。
我也遇到了类似的问题,版本是V1.1.5
你好,我们最近也在做一个列表播放视频的功能,需要引用作者的这个库,实现视频缓存和列表预加载,但是我发现在引入这个库加载数据之后,会导致列表卡顿的现象,这个问题困扰我好久了,不知道您有没有遇到这样的问题,如果您有看到我的消息,还请回复我,非常感谢~ QQ:765658769 WX:try371202
是最新的 2.0.1 版本吗?
你好,解决这个问题是修改的哪里?新到一个公司,里边用这个库比较老旧了,而且集成方式也是源码自己引入的,不知道现在的版本。我想参考一下哪里修改的来比对是否对我们公司项目是否是新的库。
我们这边现在遇到几个卡死也是因为递归锁多线程等待导致卡死的问题。 `1 libsystem_kernel.dylib ___psynch_mutexwait (in libsystem_kernel.dylib)
2 libsystem_pthread.dylib __pthread_mutex_firstfit_lock_wait (in libsystem_pthread.dylib)
3 libsystem_pthread.dylib __pthread_mutex_firstfit_lock_slow (in libsystem_pthread.dylib)
4 Foundation -[NSRecursiveLock lock] (in Foundation)
5 pregnancy -[KTVHCDataUnitPool lock] (in pregnancy:KTVHCDataUnitPool.m:285)
6 pregnancy -[KTVHCDataUnitPool archiveIfNeeded] (in pregnancy:KTVHCDataUnitPool.m:246)
7 CoreFoundation _CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER (in CoreFoundation)
8 CoreFoundation ____CFXRegistrationPost_block_invoke (in CoreFoundation)
9 CoreFoundation __CFXRegistrationPost (in CoreFoundation)
10 CoreFoundation __CFXNotificationPost (in CoreFoundation)
11 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation)
12 UIKitCore -[UIApplication _deactivateForReason:notify:] (in UIKitCore)
13 UIKitCore -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] (in UIKitCore)
14 UIKitCore -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] (in UIKitCore)
15 UIKitCore -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] (in UIKitCore)
16 UIKitCore ___186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke (in UIKitCore)
17 UIKitCore +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] (in UIKitCore)
18 UIKitCore __UISceneSettingsDiffActionPerformChangesWithTransitionContext (in UIKitCore)
19 UIKitCore -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] (in UIKitCore)
20 UIKitCore __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.615 (in UIKitCore)
21 UIKitCore -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] (in UIKitCore)
22 UIKitCore -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] (in UIKitCore)
23 UIKitCore -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] (in UIKitCore)
24 FrontBoardServices -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] (in FrontBoardServices)
25 FrontBoardServices ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 (in FrontBoardServices)
26 FrontBoardServices -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] (in FrontBoardServices)
27 FrontBoardServices ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke (in FrontBoardServices)`
线程死锁,导致主线程等待并卡死的紧急Bug报告
0x01 现象
我们有一个视频列表页面,用户滑动进行播放。并且支持预加载,就是会在当前视频播放的时候,提前下载好下个视频的1MB数据(跟此Bug应该没有关系)
用户进行视频播放,并滑动列表的时候,偶现卡死现象。表现为点击屏幕无反应。在debug状态,会导致崩溃,崩溃日志如下(详细的崩溃日志可查看附件):
0x02 Bug分析
我们连接到Xcode进行了bug复线,在卡死的时候,点击暂停查看堆栈信息,可以看到主线程卡在如下代码:
在
[self lock]
的时候一直在忙等,导致主线程卡死。经过我们的分析,发现原因如下:
线程62跟线程61之间有死锁现象。
下图是线程堆栈信息:
可以看到线程61的
[KTVHCDataUnit workingRelease]
调用了[KTVHCDataUnitPool unitShouldRearchive:]
方法,这两个方法都各自有自己的锁。然后看线程62,
[KTVHCDataUnitPool totalCacheLength]
调用了[KTVHCDataUnit cacheLength]
这两个方法都各自有自己的锁。这里就比较明白了,当两个线程同时进入各自的第一个方法,
KTVHCDataUnit
KTVHCDataUnitPool
都会上锁,然后又进行了相互调用,因为已经被锁住了,这时候去申请锁,线程61和线程62会造成死锁。下图表示线程62锁住KTVHCDataUnitPool
下图表示线程62锁住KTVHCDataUnit
下图表示线程61锁住KTVHCDataUnit
下图表示线程61锁住KTVHCDataUnitPool
那么线程61和线程62的死锁为什么会造成主线程死锁呢?
因为线程62是从KTVHCDownload类中的方法didReceiveResponse 开始调用,而didReceiveResponse 会讲KTVHCDownload锁住,然后在cleanBackgroundTaskAsync方法中的第啊吗会在主线程执行,并申请锁,这样,主线程也就卡住了。
0x03 解决
我们这边暂时还没找到合适的解决方法