UIManagedDocument hangs the main thread

Under certain circumstances UIManagedDocument blocks the main thread: I encountered this with situation when two different external writers in quick succession request coordinated write on the document’s file. After the 1st writer finishes its work, UIManagedDocument starts the revert process, and if at the same time the 2nd writer requests coordinated write, it seems that the coordinator allows the 2nd writer to begin, but then everything hangs: on Main thread UIManagedDocument waits for coordinated read, while the 2nd writer never reaches its writer block.

The problem occurs only on iOS, I get it on iPad.

I have a sample project, one of the tests result, spindump from the failed test: https://www.dropbox.com/scl/fo/qm40ano3kz15lucjj1zx3/h?rlkey=2029ge5moou7ghaqqnklsp7us&dl=0

Open the project and start the test on iPad (there is only one test: testExternalWrite), the problem may occur inconsistently.

I submitted a report in Feedback Assistant like a month ago—no reaction.

If somebody has time to take a look and say something, thank you very much!

I submitted a report in Feedback Assistant like a month ago

What was that bug number?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It turns out that the problem occurs when you have UIManagedDocument.revert() and external coordinated writing synchronized. What's more—the hanging occurs on macOS also. I simplified test to just call revert() and coordinate(writingItemAt:). If you run exactly the same test on UIDocument, everything works fine. I'm pretty sure that this is a bug in UIManagedDocument. As of now, I incline to override revert() in order to skip super's implementation of this method, because it's UIManagedDocument and, by logic, we can work with managedObjectContext.

UIManagedDocument hangs the main thread
 
 
Q