Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash RangeReplaceableCollection.append<A>(contentsOf:) #1626

Open
bgoncal opened this issue Sep 16, 2024 · 8 comments
Open

Crash RangeReplaceableCollection.append<A>(contentsOf:) #1626

bgoncal opened this issue Sep 16, 2024 · 8 comments

Comments

@bgoncal
Copy link

bgoncal commented Sep 16, 2024

What did you do?

I have a logic that every time I receive updates from an API I check if I need to replace the information from my local database which uses GRDB, for that I do something like this:

let cachedEntities: [HAAppEntity] = try Current.database().read { db in
      try HAAppEntity
          .filter(Column(DatabaseTables.AppEntity.serverId.rawValue) == server.identifier.rawValue)
          .orderByPrimaryKey()
          .fetchAll(db)
  }

But sometimes this makes the App crash in background (This logic also runs in background), in Xcode crashes I see crash "RangeReplaceableCollection.append(contentsOf:)".

What did you expect to happen?

No crash

What happened instead?

Crash

Environment

GRDB flavor(s): GRDB
GRDB version: v6.29.3
Installation method: CocoaPods
Xcode version: 16 RC
Swift version: 5.7
Platform(s) running GRDB: iOS, macOS and watchOS
macOS version running Xcode: 15.1 Beta 3

Demo Project

I don't have a demo project but the code fo my app is open source, the exact file I mentioned above is:
https://github.com/home-assistant/iOS/blob/master/Sources/App/AppEntitiesObserver.swift

Crash is pointed to be on line 52

CleanShot 2024-09-16 at 11 45 55@2x
CleanShot 2024-09-16 at 11 46 46@2x
CleanShot 2024-09-16 at 11 46 54@2x

@groue
Copy link
Owner

groue commented Sep 16, 2024

Hello @bgoncal,

Thank you for the report.

The crash report mentions swift_getAssociatedTypeWitness, which makes me think of another crash (#1619) which is due to a compiler bug regarding witness tables (see this mastodon post). You also mention Xcode 16 RC, which is another element in favor of this hypothesis.

May I ask if this crash has started happening after some change in your app, or in the way the app is built or distributed? When you compare the version that crashes and the version that does not, was has changed?

Also, please confirm that the app was built with Xcode 16 RC.

And finally, please tell which is the target iOS version of your app.

@bgoncal
Copy link
Author

bgoncal commented Sep 16, 2024

Unfortunately I just added GRDB to the App, so I don't have a previous version to compare :/
Yes the app was built with Xcode 16 RC

Minimum app version is iOS 15, crash happens (at least) on iOS 17.6 and 18

@bgoncal
Copy link
Author

bgoncal commented Sep 16, 2024

Ive never seen the issue happening in foreground, so.. perhaps it has some relation? (Even though it would be something different from what you shared above).
I just added a check to only run it in foreground to see if the issue still happens or not

@groue
Copy link
Owner

groue commented Sep 16, 2024

Thank you for the feedback.

Unfortunately I just added GRDB to the App, so I don't have a previous version to compare

Welcome to the GRDB users :-)

Minimum app version is iOS 15, crash happens (at least) on iOS 17.6 and 18

OK, so that's not #1619.

Ive never seen the issue happening in foreground, so.. perhaps it has some relation? (Even though it would be something different from what you shared above).

Eventual background errors due to data protection should turn into a runtime error that you can catch, not a hard crash (unless you use try!, of course). Quoting the doc:

When a database is protected, an application that runs in the background on a locked device won’t be able to read or write from it. Instead, it will catch DatabaseError with code SQLITE_IOERR (10) “disk I/O error”, or SQLITE_AUTH (23) “not authorized”.

I just added a check to only run it in foreground to see if the issue still happens or not

Why not: this could help narrowing the problem.

Did you try to trigger the crash on your own device?


As a temporary conclusion... Did you consider using Xcode 15.4, since Xcode 16 RC still has rough edges?

@bgoncal
Copy link
Author

bgoncal commented Sep 16, 2024

I couldn't reproduce the issue while debugging, but I see it happening in the testflight version on my personal device, usually I see "Home Assistant crashed, do you want to report the issue?" popup after I unlock my device (but before trying to open the app, just on home screen)

I cannot use 15.4 because my app has iOS 18 specific features :/

@groue
Copy link
Owner

groue commented Sep 16, 2024

I cannot use 15.4 because my app has iOS 18 specific features :/

Of course!

I couldn't reproduce the issue while debugging, but I see it happening in the testflight version on my personal device.

It would be interesting to get a full crash log stored on the device, if possible. I would also run the app, from Xcode, in Release configuration. Attach the Xcode debugger to the TestFlight build could be interesting as well.

I'm sorry if I'm throwing ideas in the air, but I'm just as clueless as you are 😅

@bgoncal
Copy link
Author

bgoncal commented Sep 16, 2024

No worries, ask for as much as you need haha, let me check the full log report and get back to you

@bgoncal
Copy link
Author

bgoncal commented Sep 17, 2024

After I added the checked for foreground the crash stopped happening, maybe too soon to tell but definitely an improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants