App opens CoreData stores when launch via Xcode, but not when launched via Finder

We have an application that has been using CoreData stores since 2009, but is suddenly having some strange behavior when the application is launched via the Finder.


The application has up to a couple hundred core data stores (sqlite with WAL) that are loaded into a single persistent store coordinator at launch. When the application is launch from within Xcode (using release or debug builds, with the debugger on or off), everything loads up fine---zero complaints. However, when the application is launch from the Finder, the first 'several' persistent stores are loaded fine, but then eventually they start failing to load. E.g.,


Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo=0x618000278d80
{NSSQLiteErrorDomain=14, NSUnderlyingException=I/O error for database at /Users/path/SomeStore.sql.  
SQLite error code:14, 'unable to open database file'}


What could possibly be going on here?


It's worth noting that the application actually creates two separate persistent store coordinators, one for main thread use and the other for background thread use, that load the same files. However, loading is synchronized so the two coordinates aren't doing this at the same time.


Also, the stores are being loaded sequentially---no weird threading going here.


Any ideas are appreciated---thanks,

Jeffrey

Did you accidentally turn on application sandboxing or something?


As far as other things which may have changed that you didn't think were important, which versions of Xcode and OS X are you using?

It's definitely sandboxed---the core data files are being created, written to, and read from its Application Support folder in the sandbox Container. Does Xcode treat the sandbox differently when launching an application?


Yes, Xcode and the OS have changed. I'll march backwards and see if I can figure out if one of those has made a difference. In other unrelated work I've found that the jump from Xcode 5 to 6 revealed a number of multithreading bugs, so I suppose this could be related.

Another key piece of evidence seems to the be that the issue is regarding the number of core data stores that are being loaded. If I prevent the application from loading so many stores, there's no issue.

This is actually ridiculously easy to reproduce using Apple's template code for CoreData, with only a few lines of modification. I posted sample code on GitHub. If you build an run it, it will create 1000 empty sql stores. It builds and runs fine from within Xcode. Now go 'Archive' the application, then run it. Now it'll fail to load. You'll see the errors pile up in the console.


This is a bug, right? Anybody see a way around this (short of using one store)?

Submitted as rdar://21439140

App opens CoreData stores when launch via Xcode, but not when launched via Finder
 
 
Q