Tencent / VasSonic

VasSonic is a lightweight and high-performance Hybrid framework developed by tencent VAS team, which is intended to speed up the first screen of websites working on Android and iOS platform.
Other
11.8k stars 1.61k forks source link

必现野指针crash #299

Closed JianboYan closed 5 years ago

JianboYan commented 5 years ago

What steps will reproduce the problem? 该问题的重现步骤是什么?

  1. 点击LOAD WITH UNSTRICT SONIC
  2. 快速点击返回后野指针

What is the expected output? What do you see instead? 你期待的结果是什么?实际看到的又是什么? 正常释放

What version of the product are you using? On what operating system? 你正在使用产品的哪个版本?在什么操作系统上? iOS12.1模拟器

Please provide any additional information below. 如果有的话,请在下面提供更多信息。

我打出了日志,请仔细看SonicResourceLoadOperation相关信息

2019-03-14 17:35:09.680193+0800 SonicSample[99744:709274] [framework] CUIThemeStore: No theme registered with id=0
2019-03-14 17:35:10.551131+0800 SonicSample[99744:709330] #SonicEventLog# resource cache path:/Users/uc/Library/Developer/CoreSimulator/Devices/ECBD0F5D-BD93-4E55-B7C9-A9DA77B198A5/data/Containers/Data/Application/BBA38F3B-B0FA-44C2-84D8-E132DB0ECAA6/Library/Caches/SonicResourceCache
2019-03-14 17:35:10.553584+0800 SonicSample[99744:709330] #SonicEventLog# event :SessionDidLoadLocalCache info:{
    dataLength = 40991;
    sessionID = 4e0cb9c48930aa9a114528d3bda52585;
    url = "http://www.kgc.cn/zhuanti/bigca.shtml?jump=1";
}
2019-03-14 17:35:10.554218+0800 SonicSample[99744:709329] delegate is <SonicResourceLoadOperation: 0x600003ca8690> request: <NSMutableURLRequest: 0x6000015a4e50> { URL: http://assets.kgc.cn/ff7f069b/css/common-min.www.kgc.css?v=e4ecfe82 }
2019-03-14 17:35:10.554227+0800 SonicSample[99744:709330] delegate is <SonicResourceLoadOperation: 0x600003cbc770> request: <NSMutableURLRequest: 0x6000015b2440> { URL: http://assets.kgc.cn/ff7f069b/css/themes.www.kgc.css?v=612eb426 }
2019-03-14 17:35:10.554314+0800 SonicSample[99744:709328] delegate is <SonicResourceLoadOperation: 0x600003ca84d0> request: <NSMutableURLRequest: 0x6000015b8d10> { URL: http://assets.kgc.cn/ff7f069b/css/style.www.kgc.css?v=05d94f84 }
2019-03-14 17:35:10.555823+0800 SonicSample[99744:709274] delegate is <SonicServer: 0x600003caa450> request: <NSMutableURLRequest: 0x6000015a4b10> { URL: http://www.kgc.cn/zhuanti/bigca.shtml?jump=1 }
2019-03-14 17:35:10.771573+0800 SonicSample[99744:709344] #SonicEventLog# protocol did load data length:40991
2019-03-14 17:35:10.771815+0800 SonicSample[99744:709344] #SonicEventLog# protocol did finish loading request:<NSMutableURLRequest: 0x6000015ae660> { URL: http://www.kgc.cn/zhuanti/bigca.shtml?jump=1 }
2019-03-14 17:35:10.826167+0800 SonicSample[99744:709347] WF: === Starting WebFilter logging for process SonicSample
2019-03-14 17:35:10.826328+0800 SonicSample[99744:709347] WF: _userSettingsForUser : (null)
2019-03-14 17:35:10.826443+0800 SonicSample[99744:709347] WF: _WebFilterIsActive returning: NO
2019-03-14 17:35:11.724760+0800 SonicSample[99744:709327] #SonicEventLog# event :SessionDestroy info:{
    sessionID = 4e0cb9c48930aa9a114528d3bda52585;
    url = "http://www.kgc.cn/zhuanti/bigca.shtml?jump=1";
}
2019-03-14 17:35:11.724906+0800 SonicSample[99744:709327] #SonicEventLog# Trim root cache in duration!
2019-03-14 17:35:11.724944+0800 SonicSample[99744:709274] SonicResourceLoadOperation: <SonicResourceLoadOperation: 0x600003ca8690> dealloced
2019-03-14 17:35:11.725055+0800 SonicSample[99744:709328] #SonicEventLog# Trim resource cache in duration!
2019-03-14 17:35:11.725060+0800 SonicSample[99744:709274] SonicResourceLoadOperation: <SonicResourceLoadOperation: 0x600003cbc770> dealloced
2019-03-14 17:35:11.725194+0800 SonicSample[99744:709274] SonicResourceLoadOperation: <SonicResourceLoadOperation: 0x600003ca84d0> dealloced
2019-03-14 17:35:11.727708+0800 SonicSample[99744:709328] Task <5CF34DF5-31E0-45FB-B68F-BBF2B51C5885>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=http://www.kgc.cn/zhuanti/bigca.shtml?jump=1, NSErrorFailingURLKey=http://www.kgc.cn/zhuanti/bigca.shtml?jump=1, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <5CF34DF5-31E0-45FB-B68F-BBF2B51C5885>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <5CF34DF5-31E0-45FB-B68F-BBF2B51C5885>.<1>, NSLocalizedDescription=cancelled} [-999]
2019-03-14 17:35:14.513260+0800 SonicSample[99744:709328] request :<NSMutableURLRequest: 0x6000015a4b10> { URL: http://www.kgc.cn/zhuanti/bigca.shtml?jump=1 }  dealloc
2019-03-14 17:35:14.518424+0800 SonicSample[99744:709328] Task <5CF34DF5-31E0-45FB-B68F-BBF2B51C5885>.<1> finished with error - code: -999
(lldb) 

备注: 看了下源码实现,是因为SonicResourceLoadOperation的dealloc方法里面没有释放掉connection,建议在最前面加一下cancel。 另外,内存管理相关的bug有点多,如果不能把握好non-ARC,还是建议使用ARC

JianboYan commented 5 years ago

附上内存泄漏的图: image

sonic-ios-dev commented 5 years ago

提交了一个修改,使用Allocation验证没有问题了。您可以使用Dev分支再验证一下。

vasdeveloper commented 5 years ago

https://github.com/Tencent/VasSonic/pull/302 已fix