filecoordinationd crashes while processing KVO

Number:rdar://34388420 Date Originated:12-Sep-2017 01:10 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 11, Xcode 9.0 beta 6 (9M214v)
Classification:Crash/Hang/Data Loss Reproducible:Sometimes
We noticed that one of our test cases, which is stress-testing document loading, occasionally triggers a crash in filecoordinationd, leading to failed coordinated reads. This appears to be due to an issue with KVO observing in filecoordinationd. When the issue occurs, we get an error on our side and also a system crash report for filecoordinationd.

Steps to Reproduce:
Our tests simply loads a lot of documents from our test pool in parallel using our PSPDFKit framework. The document is a file presenter and uses file coordination for reading.

- (void)testLoadAllDocuments {
    let allPDFAssets = [self PDFAssets];

    dispatch_apply(allPDFAssets.count, self.defaultDispatchQueue, ^(size_t index) {
        NSURL *url = allPDFAssets[index];
        let document = [PSPDFDocument documentWithContent:url];
        const BOOL isValid = document.isValid;
        if ([self isPathSupposedToBeValid:path]) {
            XCTAssertTrue(isValid, "File with path should be valid: %@", path);
        } else {

Our tests run on various iOS simulators. The failures only occur on the iOS 11 tests.

Expected Results:
The test should pass without issues. That is the current behavior on iOS 9 and iOS 10.

Actual Results:
The test occasionally fails with the following style of error on our side:

2017-09-10 21:31:22.386588-0700 PSPDFKit-TestHost-iOS[85299:30681418] [claims] F2C6B0EB-EDAA-49C0-8DB6-7E061116FB68 grantAccessClaim message failed: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named" UserInfo={NSDebugDescription=connection to service named}
2017-09-10 21:31:22.386789-0700 PSPDFKit-TestHost-iOS[85299:30681418] A process invoked one of the -[NSFileCoordinator coordinate...] methods but filecoordinationd crashed. Returning an error.
2017-09-10 21:31:22.386852-0700 PSPDFKit-TestHost-iOS[85299:30681131] [PSPDFKit] [ Warn] -[PSPDFCoordinatedFileDataProvider performCoordinatedReading:options:error:]/121 Coordinated data provider read from file:///Volumes/CI/ci/Library/Developer/CoreSimulator/Devices/38BFE303-5225-4514-AC12-8C501F090CB7/data/Containers/Bundle/Application/FBF8A480-913A-4F6A-82F1-5B693F27F217/ failed : Error Domain=NSCocoaErrorDomain Code=256 "The file “Testcase_JPG2000_Assert.pdf� couldn’t be opened." UserInfo={NSURL=file:///Volumes/CI/ci/Library/Developer/CoreSimulator/Devices/38BFE303-5225-4514-AC12-8C501F090CB7/data/Containers/Bundle/Application/FBF8A480-913A-4F6A-82F1-5B693F27F217/}.

The crash occurs at different times during the test without a noticeable pattern. The crash also logs the following in the device (simulator) console:

Sep 11 14:35:19 SpaceBook[10730] ([10987]): Service exited due to signal: Segmentation fault: 11 sent by exc handler[0]
Sep 11 14:45:23 SpaceBook[10730] ([17405]): Service exited due to signal: Segmentation fault: 11 sent by exc handler[0]

There are also crash reports generated.

iOS 11, Xcode 9.0 beta 6 (9M214v)

I’m attaching several crash reports and some output from the following command: sudo log stream --system --info --debug --predicate "subsystem contains 'filecoordination'"

A representative stack trace contains:

____NSOQOpFinished_block_invoke + 198
+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:] + 1777
NSKeyValueNotifyObserver + 116
NSKeyValueDidChange + 483
NSKeyValueDidChangeWithPerThreadPendingNotifications + 129
-[NSFileAccessProcessManager allowSuspension] + 182
-[NSFileAccessClaim devalueSelf] + 65
-[NSFileReadingClaim devalueSelf] + 153
-[NSFileAccessClaim revoked] + 573
-[NSFileAccessArbiter _revokeAccessClaimForID:fromLocal:] + 100
-[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 2706

This is a duplicate of radar #34372201


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!