Core Data error: SQLITE_IOERR_SHMOPEN; what is this?

Hi, when setting up our Core Data stack in our iOS app (manually, with a NSManagedObjectModel/Context & NSPersistentStoreCoordinator) we have reports a rare bug we haven't been able to reproduce.

Occasionally when adding a persistent store we get a NSCocoaErrorDomain 256 error (NSFileReadUnknownError) with NSSQLiteErrorDomain=4618 in the user info. That's SQLITE_IOERR_SHMOPEN , which the SQLite docs describe this way:

I/O error within the xShmMap method on the sqlite3_io_methods object while trying to open a new shared memory segment

It seems to specifically /not/ be a SQLITE_FULL error.

Do you know what type of issue can cause this? Or where/how I can start tracking this down?

Answered by DTS Engineer in 790160022

That error is indeed rarely seen. Simply by reading the error name and description, it seems that SQLite hit the error when it tried to open or create a .shm file, which is an index file for SQLite to achieve better performance.

Other than the device is short of storage, which typically triggers a SQLITE_FULL error, as you have mentioned, one common reason that triggers an I/O error is that the file is data-protected, and so your app doesn't have the permission to access it. This happens in the following cases:

  • Your app sets the data protection level to .complete, but then tries to access the file when running in the background.

  • Your app is launched into the background and tries to access the file after the user reboots and hasn't unlocked the device.

If your app can't run into the above situation, I guess you need to capture and look into a sysdiagnose to hopefully find a hint from there. To capture a sysdiagnose, see this link.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Accepted Answer

That error is indeed rarely seen. Simply by reading the error name and description, it seems that SQLite hit the error when it tried to open or create a .shm file, which is an index file for SQLite to achieve better performance.

Other than the device is short of storage, which typically triggers a SQLITE_FULL error, as you have mentioned, one common reason that triggers an I/O error is that the file is data-protected, and so your app doesn't have the permission to access it. This happens in the following cases:

  • Your app sets the data protection level to .complete, but then tries to access the file when running in the background.

  • Your app is launched into the background and tries to access the file after the user reboots and hasn't unlocked the device.

If your app can't run into the above situation, I guess you need to capture and look into a sysdiagnose to hopefully find a hint from there. To capture a sysdiagnose, see this link.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Core Data error: SQLITE_IOERR_SHMOPEN; what is this?
 
 
Q