Skip to content

App crashes with NSRangeException after inserting record being observed by FirebaseTableViewDataSource #129

@chadpav

Description

@chadpav

Environment

  • Using FirebaseUI/Database subspec only
  • Swift 2.3 / Xcode 8 GM
  • Targeting and deploying to iOS version 9.3.5
  • Firebase SDK version: 3.5.2
  • FirebaseUI version: 0.5.x
  • CocoaPods Version: 1.0.1

The problem:

App crashes after inserting a record into database using FirebaseTableViewDataSource. Can not reproduce on 0.4.0, reliably reproduces on >=0.5.0 (although not every time).

Steps to reproduce:

  1. Create FirebaseTableViewDataSource to back a UITableView. (I'm using a queryOrderedByPriority)
  2. Insert a record or maybe up to 15 into the database that will result in Inserting a record into the tableview datasource.
  3. If needed Insert / Delete until it crashes. Sometimes it's every time an other times it's maybe a dozen inserts in.

Observed Results:

  • App crashes often but not every time. The Insert does succeed so this is happening when the ChildAdded event is coming back to Insert the new record into the internal Array. I believe the code is expecting to find the PrevChild in the array but for some reason the array doesn't contain the item anymore. This explains the index 9223372036854775808 and the bounds [0..0] don't make any sense because there should have already been 1 record in that array. I just crashed the app again and the array bounds were 1 off (0...3) when I had 5 records in the database. Note, it took me about 10 tries to crash the app this time.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 9223372036854775808 beyond bounds [0 .. 0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000105740d85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001051b4deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000105601cc5 -[__NSArrayM insertObject:atIndex:] + 901
    3   Kitchen Wall                        0x0000000101c7c372 __30-[FirebaseArray initListeners]_block_invoke.185 + 257
    4   Kitchen Wall                        0x0000000101c5402f __43-[FChildEventRegistration fireEvent:queue:]_block_invoke64 + 88
    5   libdispatch.dylib                   0x0000000106391d9d _dispatch_call_block_and_release + 12
    6   libdispatch.dylib                   0x00000001063b23eb _dispatch_client_callout + 8
    7   libdispatch.dylib                   0x000000010639a1ef _dispatch_main_queue_callback_4CF + 1738
    8   CoreFoundation                      0x000000010569a0f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    9   CoreFoundation                      0x000000010565bb99 __CFRunLoopRun + 2073
    10  CoreFoundation                      0x000000010565b0f8 CFRunLoopRunSpecific + 488
    11  GraphicsServices                    0x0000000106aa4ad2 GSEventRunModal + 161
    12  UIKit                               0x00000001037c6f09 UIApplicationMain + 171
    13  Kitchen Wall                        0x0000000101b0a6d2 main + 114
    14  libdyld.dylib                       0x00000001063e692d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Expected Results:

  • If I roll back to 0.4.0 I can reliably insert/delete/update records without a crash.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions