Repository: firebase/firebase-ios-sdk (language: cpp)

Issue:
RTDB getData Crashes When Offline
<!-- DO NOT DELETE
validate_template=true
template_path=.github/ISSUE_TEMPLATE/bug_report.md
-->
### [REQUIRED] Step 1: Describe your environment

  * Xcode version: 12.5.1
  * Firebase SDK version: 8.2.0
  * Installation method: `CocoaPods
  * Firebase Component:  Database

### [REQUIRED] Step 2: Describe the problem

Performing a getData call while not connected to the internet produces the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FChildrenNode node]: unrecognized selector sent to instance

#### Steps to reproduce:
Make any getData call while not connected to the internet


Discussion / hints:
Sorry about the trouble. Please share the full backtrace of the crash and if feasible, a reproducible example.
I cannot share a full stack trace into our codebase but here it is from the point of entry into the Firebase framework

https://user-images.githubusercontent.com/81970493/124939094-69c4af80-dfe3-11eb-921e-93d499debdec.png

Additional information if it helps, the requested data does in fact already exist in the cache and can be retrieved with an observeSingleCall
Can you share the exception message?
```
	0   CoreFoundation                      0x000000018b177270 37A3D601-9398-3DC2-9D00-1B162726A4C9 + 1159792
	1   libobjc.A.dylib                     0x000000019ef0c480 objc_exception_throw + 56
	2   CoreFoundation                      0x000000018b086278 37A3D601-9398-3DC2-9D00-1B162726A4C9 + 172664
	3   CoreFoundation                      0x000000018b1798b8 37A3D601-9398-3DC2-9D00-1B162726A4C9 + 1169592
	4   CoreFoundation                      0x000000018b17b85c _CF_forwarding_prep_0 + 92
	5   FirebaseDatabase                    0x0000000103acd0f8 -[FIRDataSnapshot value] + 80
	6   [Redacted]                   0x000000010082ea98 $s10[REDACTED]9RTDBRelayC7getData4with3for7closureySS_SaySSGySDySSyXlGctFys5Error_pSg_So15FIRDataSnapshotCtcfU_ + 232
	7   [REDACTED]                          0x000000010082ef58 $ss5Error_pSgSo15FIRDataSnapshotCIeggg_So7NSErrorCSgADIeyByy_TR + 136
	8   FirebaseDatabase                    0x0000000103b032f0 __37-[FRepo getData:withCompletionBlock:]_block_invoke + 896
	9   FirebaseDatabase                    0x0000000103af152c __63-[FPersistentConnection getDataAtPath:withParams:withCallback:]_block_invoke + 368
	10  libdispatch.dylib                   0x000000010478132c _dispatch_client_callout + 16
	11  libdispatch.dylib                   0x0000000104783fd0 _dispatch_continuation_pop + 524
	12  libdispatch.dylib                   0x0000000104797850 _dispatch_source_invoke + 1432
	13  libdispatch.dylib                   0x00000001047881d0 _dispatch_lane_serial_drain + 304
	14  libdispatch.dylib                   0x0000000104789010 _dispatch_lane_invoke + 448
	15  libdispatch.dylib                   0x0000000104794820 _dispatch_workloop_worker_thread + 1448
	16  libsystem_pthread.dylib             0x00000001d36195bc _pthread_wqthread + 272
	17  libsystem_pthread.dylib             0x00000001d361c86c start_wqthread + 8
)
2021-07-21 10:21:16.842276-0230 [REDACTED] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FChildrenNode node]: unrecognized selector sent to instance 0x2834de900'
*** First throw call stack:
(0x18b17725c 0x19ef0c480 0x18b086278 0x18b1798b8 0x18b17b85c 0x103acd0f8 0x10082ea98 0x10082ef58 0x103b032f0 0x103af152c 0x10478132c 0x104783fd0 0x104797850 0x1047881d0 0x104789010 0x104794820 0x1d36195bc 0x1d361c86c)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FChildrenNode node]: unrecognized selector sent to instance 0x2834de900'
terminating with uncaught exception of type NSException
```
Something's off about this stack trace; the referenced receiver/selector that caused the unrecognized selector exception don't appear in the stack trace. Can you share a sample project that reproduces this issue or otherwise share more debug information?
I'm experiencing the same crash. 

Here are some more details:

The crash happens not on the call to `getData` itself, but when trying to access the snapshot's value in the completion closure.

Calling either `snapshot.exists()` or `snapshot.value` triggers the crash: `'-[FChildrenNode node]: unrecognized selector sent to instance`. It doesn't seem to matter what's the data in the snapshot - I tried with a leaf node and a dictionary, same result. 
`observeSingleEvent` for the same ref under the same conditions works with no issues. 
 
The crashing line is on FIRDataSnapshot.m:40:
<img width="649" alt="Screenshot 2021-07-21 at 20 51 08" src="https://user-images.githubusercontent.com/11408899/126543610-b1004e5b-a92e-4530-baa5-9e30b828f569.png">



@hybridcattt what version of Database are you using? Can you share logs from Firebase leading up to the crash or a stack trace?
> @hybridcattt what version of Database are you using? Can you share logs from Firebase leading up to the crash or a stack trace?

I was on 8.0.0 originally, but now updated to 8.4.0 and there's no change in behaviour. 

How can I provide more logs? There's nothing printed to the console prior to the crash.

If I observe a node that's a dictionary: 
The crash itself is caused by the fact that `FIRDataSnapshot` expects `FIndexedNode`, but is passed `FChildrenNode` instead. 

If I observe a node that's a leaf node:
`FIRDataSnapshot` gets `FLeafNode` instead of `FIndexedNode`, and the crash is instead `-[FLeafNode node]: unrecognized selector sent to instance 0x10831e4b0`. 

The crash happens _after_ `getData` finishes, inside the callback, when trying to access `snapshot.value`. So the stack trace won't show much.

Here's the stack trace:
```
<_NSCallStackArray 0x10ca2c8b0>(
0   ???                                 0x000000010fe88918 0x0 + 4561864984,
1   XXX                     0x00000001029e5280 main + 0,
2   CoreFoundation                      0x00000001998e92ac 4FBDF167-161A-324C-A233-D516922C67E5 + 1229484,
3   CoreFoundation                      0x00000001998eb5b0 _CF_forwarding_prep_0 + 96,
4   XXX                                 0x0000000102fe57e0 -[FIRDataSnapshot value] + 64,
5   XXX                                   0x0000000102abe63c $s15XXX14AppCoordinatorC5start6windowySo8UIWindowC_tFyycfU_ys5Error_pSg_So15FIRDataSnapshotCtcfU_yycfU_ + 84,
6  XXX                                   0x000000010290e638 $sIeg_IeyB_TR + 52,
7   libdispatch.dylib                   0x00000001055640b4 _dispatch_call_block_and_release + 32,
8   libdispatch.dylib                   0x0000000105565de0 _dispatch_client_callout + 20,
9   libdispatch.dylib                   0x00000001055760a8 _dispatch_main_queue_callback_4CF + 1040,
10  CoreFoundation                      0x0000000199860398 4FBDF167-161A-324C-A233-D516922C67E5 + 668568,
11  CoreFoundation                      0x000000019985a270 4FBDF167-161A-324C-A233-D516922C67E5 + 643696,
12  CoreFoundation                      0x0000000199859360 CFRunLoopRunSpecific + 600,
13  GraphicsServices                    0x00000001b0e97734 GSEventRunModal + 164,
14  UIKitCore                           0x000000019c2d4584 33B02AB5-5DAF-3249-8DC6-5872DF830EC5 + 12363140,
15  UIKitCore                           0x000000019c2d9df4 UIApplicationMain + 168,
16  XXX                                   0x00000001029e52d4 main + 84,
17  libdyld.dylib                       0x0000000199515cf8 E574A365-9878-348A-8E84-91E163CFC128 + 7416
)
```

Here's a better look with other threads included:
<img width="795" alt="Screenshot 2021-07-22 at 20 33 43" src="https://user-images.githubusercontent.com/11408899/126691255-c841e781-84b6-406f-951f-000e1d6e562b.png">
<img width="809" alt="Screenshot 2021-07-22 at 20 36 15" src="https://user-images.githubusercontent.com/11408899/126691272-f38c4a3f-36f7-4f9c-bd9b-acc7a162d1e0.png">

I'm not able to reproduce this in the Database unit tests or quickstart sample. If you can reproduce this crash with the debugger attached, can you add a breakpoint in the `-[FIRDataSnapshot initWithRef:indexedNode:]` method with the following condition

```objc
![node isMemberOfClass:[FIndexedNode class]];
```
and then add the action `bt all` (debugger command), then share the console output from both cases of reproing the crash?

@morganchen12 sure:

Leaf node:
```
thread #1, queue = 'com.apple.main-thread'
    frame #0: 0x000000010b54ce7e libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000010b54d1f0 libsystem_kernel.dylib`mach_msg + 60
    frame #2: 0x0000000108ffc854 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000108ff6e99 CoreFoundation`__CFRunLoopRun + 1657
    frame #4: 0x0000000108ff64d2 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #5: 0x000000010dc292fe GraphicsServices`GSEventRunModal + 65
    frame #6: 0x0000000113960fc2 UIKitCore`UIApplicationMain + 140
    frame #7: 0x000000010052729b MyApp-pro-DEBUG`main at AppDelegate.swift:22:7
    frame #8: 0x000000010b230541 libdyld.dylib`start + 1
    frame #9: 0x000000010b230541 libdyld.dylib`start + 1
  thread #2
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
* thread #3, queue = 'FirebaseWorker', stop reason = breakpoint 8.1
  * frame #0: 0x0000000100c2b8e6 MyApp-pro-DEBUG`-[FIRDataSnapshot initWithRef:indexedNode:](self=0x00007fa4d6eb1a50, _cmd="initWithRef:indexedNode:", ref=0x00007fa4d6f2c7a0, node=0x00007fa4d6fc7eb0) at FIRDataSnapshot.m:31:12
    frame #1: 0x0000000100c63cc8 MyApp-pro-DEBUG`__37-[FRepo getData:withCompletionBlock:]_block_invoke(.block_descriptor=0x00007fa4d4fd21b0, status=@"failed", data=0x0000000000000000, errorReason=@"Client is offline.") at FRepo.m:563:27
    frame #2: 0x0000000100c507ff MyApp-pro-DEBUG`__63-[FPersistentConnection getDataAtPath:withParams:withCallback:]_block_invoke(.block_descriptor=0x00007fa4d4fa11f0) at FPersistentConnection.m:876:15
    frame #3: 0x000000010b1bbdb5 libdispatch.dylib`_dispatch_client_callout + 8
    frame #4: 0x000000010b1bec95 libdispatch.dylib`_dispatch_continuation_pop + 552
    frame #5: 0x000000010b1d0e93 libdispatch.dylib`_dispatch_source_invoke + 2249
    frame #6: 0x000000010b1c3046 libdispatch.dylib`_dispatch_lane_serial_drain + 299
    frame #7: 0x000000010b1c3e9c libdispatch.dylib`_dispatch_lane_invoke + 425
    frame #8: 0x000000010b1cdea3 libdispatch.dylib`_dispatch_workloop_worker_thread + 733
    frame #9: 0x000000010b5cf499 libsystem_pthread.dylib`_pthread_wqthread + 314
    frame #10: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #4
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #5
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #6
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #7, name = 'com.apple.uikit.eventfetch-thread'
    frame #0: 0x000000010b54ce7e libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000010b54d1f0 libsystem_kernel.dylib`mach_msg + 60
    frame #2: 0x0000000108ffc854 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000108ff6e99 CoreFoundation`__CFRunLoopRun + 1657
    frame #4: 0x0000000108ff64d2 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #5: 0x00000001052e1f88 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 277
    frame #6: 0x00000001052e218a Foundation`-[NSRunLoop(NSRunLoop) runUntilDate:] + 79
    frame #7: 0x0000000113a51437 UIKitCore`-[UIEventFetcher threadMain] + 118
    frame #8: 0x00000001052f724b Foundation`__NSThread__start__ + 1197
    frame #9: 0x000000010b5d2950 libsystem_pthread.dylib`_pthread_start + 224
    frame #10: 0x000000010b5ce47b libsystem_pthread.dylib`thread_start + 15
  thread #8
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #9
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #10
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #11, name = 'AVAudioSession Notify Thread'
    frame #0: 0x000000010b54ce7e libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x000000010b54d1f0 libsystem_kernel.dylib`mach_msg + 60
    frame #2: 0x0000000108ffc854 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000108ff6e99 CoreFoundation`__CFRunLoopRun + 1657
    frame #4: 0x0000000108ff64d2 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #5: 0x000000011c9342f4 AVFAudio`GenericRunLoopThread::Entry(void*) + 158
    frame #6: 0x000000011c959f7f AVFAudio`CAPThread::Entry(CAPThread*) + 77
    frame #7: 0x000000010b5d2950 libsystem_pthread.dylib`_pthread_start + 224
    frame #8: 0x000000010b5ce47b libsystem_pthread.dylib`thread_start + 15
  thread #14
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
  thread #15
    frame #0: 0x000000010b54e53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000010b5cf4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000010b5ce467 libsystem_pthread.dylib`start_wqthread + 15
```


Dictionary (with plain values)
```
 thread #1, queue = 'com.apple.main-thread'
    frame #0: 0x00000001131b8e7e libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x00000001131b91f0 libsystem_kernel.dylib`mach_msg + 60
    frame #2: 0x0000000110d82854 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000110d7ce99 CoreFoundation`__CFRunLoopRun + 1657
    frame #4: 0x0000000110d7c4d2 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #5: 0x00000001158952fe GraphicsServices`GSEventRunModal + 65
    frame #6: 0x000000011b6e8fc2 UIKitCore`UIApplicationMain + 140
    frame #7: 0x00000001082ad32b MyApp-pro-DEBUG`main at AppDelegate.swift:22:7
    frame #8: 0x0000000112e9c541 libdyld.dylib`start + 1
  thread #2
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #3
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #4
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #5
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #6, name = 'com.apple.uikit.eventfetch-thread'
    frame #0: 0x00000001131b8e7e libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x00000001131b91f0 libsystem_kernel.dylib`mach_msg + 60
    frame #2: 0x0000000110d82854 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000110d7ce99 CoreFoundation`__CFRunLoopRun + 1657
    frame #4: 0x0000000110d7c4d2 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #5: 0x000000010d067f88 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 277
    frame #6: 0x000000010d06818a Foundation`-[NSRunLoop(NSRunLoop) runUntilDate:] + 79
    frame #7: 0x000000011b7d9437 UIKitCore`-[UIEventFetcher threadMain] + 118
    frame #8: 0x000000010d07d24b Foundation`__NSThread__start__ + 1197
    frame #9: 0x000000011323e950 libsystem_pthread.dylib`_pthread_start + 224
    frame #10: 0x000000011323a47b libsystem_pthread.dylib`thread_start + 15
  thread #7
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #8
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
* thread #9, queue = 'FirebaseWorker', stop reason = breakpoint 8.1
  * frame #0: 0x00000001089b18e6 MyApp-pro-DEBUG`-[FIRDataSnapshot initWithRef:indexedNode:](self=0x00007f8808acfff0, _cmd="initWithRef:indexedNode:", ref=0x00007f8808e3a620, node=0x00007f880a70d780) at FIRDataSnapshot.m:31:12
    frame #1: 0x00000001089e9cc8 MyApp-pro-DEBUG`__37-[FRepo getData:withCompletionBlock:]_block_invoke(.block_descriptor=0x00007f880a660800, status=@"failed", data=0x0000000000000000, errorReason=@"Client is offline.") at FRepo.m:563:27
    frame #2: 0x00000001089d67ff MyApp-pro-DEBUG`__63-[FPersistentConnection getDataAtPath:withParams:withCallback:]_block_invoke(.block_descriptor=0x00007f880a2afaf0) at FPersistentConnection.m:876:15
    frame #3: 0x0000000112e27db5 libdispatch.dylib`_dispatch_client_callout + 8
    frame #4: 0x0000000112e2ac95 libdispatch.dylib`_dispatch_continuation_pop + 552
    frame #5: 0x0000000112e3ce93 libdispatch.dylib`_dispatch_source_invoke + 2249
    frame #6: 0x0000000112e2f046 libdispatch.dylib`_dispatch_lane_serial_drain + 299
    frame #7: 0x0000000112e2fe9c libdispatch.dylib`_dispatch_lane_invoke + 425
    frame #8: 0x0000000112e39ea3 libdispatch.dylib`_dispatch_workloop_worker_thread + 733
    frame #9: 0x000000011323b499 libsystem_pthread.dylib`_pthread_wqthread + 314
    frame #10: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #10
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #11
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #12, name = 'AVAudioSession Notify Thread'
    frame #0: 0x00000001131b8e7e libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x00000001131b91f0 libsystem_kernel.dylib`mach_msg + 60
    frame #2: 0x0000000110d82854 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x0000000110d7ce99 CoreFoundation`__CFRunLoopRun + 1657
    frame #4: 0x0000000110d7c4d2 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #5: 0x00000001246bc2f4 AVFAudio`GenericRunLoopThread::Entry(void*) + 158
    frame #6: 0x00000001246e1f7f AVFAudio`CAPThread::Entry(CAPThread*) + 77
    frame #7: 0x000000011323e950 libsystem_pthread.dylib`_pthread_start + 224
    frame #8: 0x000000011323a47b libsystem_pthread.dylib`thread_start + 15
  thread #15
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #16
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
  thread #17
    frame #0: 0x00000001131ba53e libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x000000011323b4fd libsystem_pthread.dylib`_pthread_wqthread + 414
    frame #2: 0x000000011323a467 libsystem_pthread.dylib`start_wqthread + 15
```

<!-- event: mark-stale -->
Hey @ChristianGoodridgeLVM. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!
The issue is still relevant
Apologies for the slow updates. I have a hunch of what's causing this to crash, but don't have the root cause yet. I'll add some logging in the next release (M102) to make this crash happen at the assignment site rather than the access site so it will be more clear where the failure occurs.
@morganchen12 deal. Let me know if you need me to reproduce again. 
@hybridcattt if you have extra time, you can patch in the changes from https://github.com/firebase/firebase-ios-sdk/pull/8470 and test them locally. This should provide a clearer picture of the crash.
@morganchen12  I tried it out, and the inserted block of code is not being entered. 

I did some more debugging. `FCacheNode` contains `FIndexedNode` which in turn contains `FChildrenNode` in its `node` property. So the check you added passes. 

The issue is in how it's then used:

Look at FRepo.m line 545/546. 
```
FIndexedNode *node =
                   [self.serverSyncTree persistenceServerCache:querySpec];
```
`node` variable here ends up containing `FChildrenNode` instead. 

This is because `FCacheNode` implements its `node` like this: (FCacheNode.m:66)
```
- (id<FNode>)node {
    return self.indexedNode.node;
}
```

So when FSyncTree returns a node, it ends up returning not `FIndexedNode` but what's inside it: (FSyncTree.m:728)
```
- (FIndexedNode *)persistenceServerCache:(FQuerySpec *)querySpec {
    FCacheNode *cacheNode =
        [self.persistenceManager serverCacheForQuery:querySpec];
    if (cacheNode == nil || cacheNode.node.isEmpty) {
        return nil;
    }
    return cacheNode.node; // <----- here
// should be return cacheNode.indexedNode ? 
}
```
And this `persistenceServerCache` function here is _only_ used from `getData:`. From what I can see it should just return  `cacheNode.indexedNode` instead.
It seems to work well.


Fix patch:
diff --git a/FirebaseDatabase/Sources/Core/FSyncTree.m b/FirebaseDatabase/Sources/Core/FSyncTree.m
index 791ac02829a..864e96edfcd 100644
--- a/FirebaseDatabase/Sources/Core/FSyncTree.m
+++ b/FirebaseDatabase/Sources/Core/FSyncTree.m
@@ -731,7 +731,7 @@ - (FIndexedNode *)persistenceServerCache:(FQuerySpec *)querySpec {
     if (cacheNode == nil || cacheNode.node.isEmpty) {
         return nil;
     }
-    return cacheNode.node;
+    return cacheNode.indexedNode;
 }
 
 - (id<FNode>)getServerValue:(FQuerySpec *)query {


Test patch: