请求有时在 iOS9 nsurlstoraged 中延迟最多 1 分钟 - NSURLStorageURLCacheDB 删除所有响应数据库已锁定

Requests delayed up to 1min sometimes in iOS9 nsurlstoraged - NSURLStorageURLCacheDB deleteAllResponses database locked

自 iOS 9 以来,我们一直在应用程序处理请求返回时重现这些巨大的延迟/应用程序启动正常,View Controllers 和一切。我能够与该应用程序交互,但在某些情况下它不会加载所有请求中的一部分。它只发生在 iOS9 设备中(它是针对 iOS8 还是 iOS9 构建的并不重要)。

我们唯一的线索是每次发生这种情况时都会重复此日志:

Oct 2 15:21:15 Hurts-iPhone ondemandd[1364] <Error>: -[ODRBackgroundMaintenance startBackgroundMaintenanceOperations]
Oct 2 15:21:20 Hurts-iPhone nsurlstoraged[107] <Warning>: ERROR: NSURLStorageURLCacheDB deleteAllResponses: dbConnection=0x188dd200 DB=/private/var/mobile/Containers/Data/Application/5CD0BB06-3EF9-4A76-B5AF-25C86A8FA2AC/Library/Caches/com.company.bundleId/Cache.db Delete from cfurl_cache_blob_data failed:database is locked ErrCode: 5.
Oct 2 15:21:31 Hurts-iPhone nsurlstoraged[107] <Warning>: ERROR: NSURLStorageURLCacheDB deleteAllResponses: dbConnection=0x188dd200 DB=/private/var/mobile/Containers/Data/Application/5CD0BB06-3EF9-4A76-B5AF-25C86A8FA2AC/Library/Caches/com.company.bundleId/Cache.db Delete from cfurl_cache_receiver_data failed:database is locked ErrCode: 5.
Oct 2 15:21:31 Hurts-iPhone nsurlstoraged[107] <Error>: Error: execSQLStatement:onConnection:toCompletionWithRetry:writeLockHelp - SQL=COMMIT;, error-code=1, error-message=cannot commit - no transaction is active
Oct 2 15:21:31 Hurts-iPhone nsurlstoraged[107] <Warning>: ERROR: NSURLStorageURLCacheDB deleteAllResponses: dbConnection=0x188dd200 DB=/private/var/mobile/Containers/Data/Application/5CD0BB06-3EF9-4A76-B5AF-25C86A8FA2AC/Library/Caches/com.company.bundleId/Cache.db Commit transaction failed:cannot commit - no transaction is active ErrCode: 1.
Oct 2 15:21:34 Hurts-iPhone kernel[0] <Notice>: IOAccessoryManager::configureAllowedFeatures: tristar: revoking mask=0xffff
Oct 2 15:21:34 Hurts-iPhone iaptransportd[29] <Warning>: CIapPortAppleIDBus: Auth timer timeout completed on pAIDBPort:0x17d4a4e0, portID:01 downstream port
Oct 2 15:21:41 Hurts-iPhone nsurlstoraged[107] <Warning>: ERROR: NSURLStorageURLCacheDB deleteAllResponses: dbConnection=0x188dd200 DB=/private/var/mobile/Containers/Data/Application/5CD0BB06-3EF9-4A76-B5AF-25C86A8FA2AC/Library/Caches/com.company.bundleId/Cache.db Vacuum failed:database is locked ErrCode: 5

我见过的具有相同行为的唯一案例是在 Mac OS X 中使用本机应用程序(邮件、iTunes 等),这使它更加奇怪。

延迟请求似乎可以缓解这些情况。这绝对是 iOS 上的一个僵局,但我们很乐意解决这个问题。

我也遇到了同样的问题。但在这种情况下,我的应用程序因消息应用程序而崩溃 - 'UIKitApplication:com.companyname.com[0xrhel]' 被 jetsam 杀死。

我去掉了cache.db,好像还可以


我认为这不是一个好的解决方案,但它确实有效。

我终于找到了一个解决方案,一开始就从应用程序中删除了缓存。我们不会大量使用应用程序缓存,因此在我们的例子中,就性能而言,这不是一个昂贵的解决方案。删除缓存的方法是在应用程序启动时设置一个空缓存

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:0
                                                     diskCapacity:0
                                                         diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];

我希望这对其他人有帮助。

与此同时,Apple 方面有一些未解决的错误报告。当我得到更多关于它的信息时,我会 post 在这里。