Strange behavior of CoreData's '-com.apple.CoreData.ConcurrencyDebug 1' option

Originator:kentaro.matsumae
Number:rdar://26890268 Date Originated:20-Jun-2016 08:51 PM
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification: Reproducible:
 
Summary:
CoreData's '-com.apple.CoreData.ConcurrencyDebug 1' option breaks in unexpected line. 

Fully reproduce code is here:
https://github.com/kenmaz/CoreDataVioration/tree/master

I have two CoreData Entities, EntityA and EntityB.

NSManagedObjectContext hierarchy is here:
- RootSaving Context ( private queue) 
  - Main Context ( main queue )
    - Private Context (private queue) 

In my sample code, execute three code blocks in parallel.
#1 In private queue, insert and save EntityA record
#2 In main queue, fetch EntityB record
#3 in main queue, fetch EntityA record

I think #2 and #3 run in serial because I use main queue and perofmBlock: method.
 
Xcode stop in #3 code block with EXC_BAD_INSTRUCTION.
I can see "__Multithreading_Violation_AllThatIsLeftToUsIsHonor__" in stack trace, so I think this breaks cuased by CoreData's ConcurrencyDebug option.

I don't know why ConcurrencyDebug option stops my code.

If you turn off ConcurrencyDebug option, this code works fine.

Steps to Reproduce:
1. Clone sample code from: 
https://github.com/kenmaz/CoreDataVioration/tree/master

2. Open CoreDataViolationCrash.xcodeproj with Xcode

3. Edit Scheme > Run > Argument Passed on Launch >

4. Add "-com.apple.CoreData.ConcurrencyDebug 1"

5. Run with simulator (cmd+R)

6. Press 'button' button once or twice on main screen.

7. Xcode stop the execution on following line:

Expected Results:
Xcode don't stop execution.

Actual Results:
Xcode stop execution.

Version:
iOS 9.3.2

Notes:


Configuration:
Xcode 7.3 (7D175) + Mac OSX 10.11.4 + iPhone6s simulator / iPhone6 actual device

Comments

You can avoid this strange behavior with comment out following line:

// req.fetchBatchSize = 20; or

// req.predicate = [NSPredicate predicateWithFormat:@"foo = %@", @"wwww"]; But I don't know why this workaound works.

By kentaro.matsumae at June 20, 2016, 12:14 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!