Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(NSFetchedResultsController): couldn't read cache file to update store info timestamps

I upgraded my project to Xcode 8. Now, I'm getting this error log with Xcode 8 and iOS 10 combination.

Setting the cacheName to nil in the below code seems fix it.

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:NULL cacheName:@"myCache"]; 

What should I do to get rid of this error log and use cache in my FRC?

like image 877
iCanCode Avatar asked Sep 21 '16 15:09

iCanCode


1 Answers

This error should not be ignored because it can cause app crash. It is related to an iOS 10 bug of file descriptor leaks. There are reports on openradar and Apple Bug Reporter.

What happen: if you load a view controller using NSFetchedResultsController with a non-nil cacheName, every time you save the managed object context you will open one or more file descriptors pointing to the sectionInfo cache file of the fetchedResultsController. This means that if you save context 255 times, you will reach the maximum number of files that can be opened on devices and no new resources may be opened, causing any subsequent opening of xib files, images, database, etc. to fail.

The problem occurs also for apps already on production (built with xcode 7) on devices upgraded to iOS 10.

A temporary solution is disabling NSFetchedResultsController caching with nil as cacheName:

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:NULL cacheName:nil]; 

Obviously in this way we can't get advantage of caching. I hope Apple will fix the bug asap. I am going to test against 10.2 beta 1.

OPEN RADAR 28361550

EDIT On iOS 10.2 beta 1 the bug does not occur: it has been solved (for now).

like image 68
Donnit Avatar answered Oct 02 '22 07:10

Donnit