sandbox_extension_consume error

I have a sandboxed, document-based app. Things usually work as intended, but sometimes the app crashes with EXC_BAD_ACCESS, after producing multiple sandbox errors.

I haven't found any information about the specific errors or on how to avoid them.

 [scoped] handle 0: sandbox_extension_release error [22: Invalid argument]
Appname [96446:12385639] [scoped] <0x600002e4ba20 file:///....(url here)>: internal sandbox error for <StopAccessing>
Appname[96446:12386186] [scoped] Scoped bookmarks can only be created for existing files or directories
Appname[96446:12386810] [default] sandbox_extension_consume returned 12
sandbox_extension_consume returned 12
sandbox_extension_consume returned 12

... ad nauseam

I'm not using any custom writing methods in my NSDocument subclass and the URL that it has accessed before stopping access, does in fact exist.

The most cryptic error is sandbox_extension_consume returned 12. There is no information about it available anywhere, and until recently, it didn't cause any problems, but now it has started crashing the app, giving the aforementioned bad access.

What am I doing wrong and where? What is sandbox_extension_consume and why does it return 12?

I would try to understand why you get this massage:     "Scoped bookmarks can only be created for existing files or directories". If you are sure you access only valid directories or files, you should file a bug report or contact support to find what the error message is about.

I am quite sure about that, because I only rely on NSDocumentController to serve me the files. If I understand correctly, NSDocument should support sandboxing out-of-the-box?

I can suppress "Scoped bookmarks can only be created for existing files or directories" by overriding autosavedContentsFileURL and creating a blank file before returning its URL, but it doesn't seem to affect the sandbox_extension_consume 12 error.

For some reason I can't edit the question, but further investigations pointed out that the bad access crash was not related to the sandbox extension error. BUT – after opening couple of documents, this error stops the app from saving anything, including even the files that were already open. It happens quite randomly, and gives out an alert saying that the file can't be accessed. All files which are open are then deadlocked.

I've seen sandbox_extension_consume error also. Have you learned anything more since posting?

sandbox_extension_consume error
 
 
Q