Skip to content

Realm init crash in xcode16. #8756

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

Open
kirin233x opened this issue Apr 11, 2025 · 2 comments
Open

Realm init crash in xcode16. #8756

kirin233x opened this issue Apr 11, 2025 · 2 comments

Comments

@kirin233x
Copy link

How frequently does the bug occur?

Always

Description

I am currently encountering a rather strange issue.

When I open a Realm file, for example, Conversation.realm, which only contains ConversationModel. I am using the following code:

Swift

  _ = try? Realm()
  var config = Realm.Configuration.defaultConfiguration
  config.fileURL!.deleteLastPathComponent()
  config.fileURL!.appendPathComponent(self.fileName)
  config.fileURL!.appendPathExtension("realm")
  config.encryptionKey = encryptionKey
  config.readOnly = readOnly
  config.schemaVersion = UInt64(schemaVersion)
  config.migrationBlock = migration

However, Realm crashes during startup, and the reason for the crash is that the database tables in another .realm file haven't been upgraded.

Error Reason

m_reason  const std::string "Migration is required due to the following errors:\n- Property 'DBGroupInfo.nick_name' has been added.\n- Property 'DBGroupMember.nick_name' has been added.

However, in reality, the database migrations for both of these tables(DBGroupInfo.realm, DBGroupMemeber.realm) do have separate migrationBlocks defined to add the new fields.

So I don't understand why, when opening Conversation.realm, it checks the migration fields of other Realm files.

This error only started occurring after Xcode 16.2; it was working normally in previous versions.

The Realm Swift version I am using is 10.43.0.

Stacktrace & log output

0 Realm realm::Exception::what() const (in Realm) + 128 0x10f360000 + 1754708
1 Realm makeError(realm::Exception const&) (in Realm) (RLMError.mm:179) 0x10f360000 + 209412
2 Realm RLMRealmTranslateException(NSError* __autoreleasing*) (in Realm) (RLMRealm.mm:166) 0x10f360000 + 1216620
3 Realm +[RLMRealm realmWithConfiguration:confinedTo:error:] (in Realm) (RLMRealm.mm:0) 0x10f360000 + 1223140
4 Realm +[RLMRealm realmWithConfiguration:queue:error:] (in Realm) (RLMRealm.mm:391) 0x10f360000 + 1219764

Can you reproduce the bug?

Always

Reproduction Steps

Okay, here is the translation of those steps:

Build an app containing multiple Realm databases using Xcode 14.2, realm-swfit:10.13
Install a new version of the app over the existing one, which includes Realm field updates migrated via migrationBlock.
Open the app using Xcode 16.2. The app crashes immediately (force closes). realm-swift:10.43.0

Version

10.43.0

What Atlas Services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

iOS 18.3.1

Build environment

Xcode version: 16.2
Dependency manager and version: realm-swift:10.43.0

@kirin233x
Copy link
Author

Initially, the stack trace for this problem was confusing. Later, I found an issue that addressed the stack trace problem: realm/realm-core#7998. This indicated that when the exception was being thrown/propagated to Objective-C, another exception occurred, leading to a crash when what() was called. In short, an exception occurred during exception handling.

By continuously rolling back versions to find out what was triggering the exception, I eventually discovered the impact of the database migration.

So, if you encounter the issue where it crashes inside what(), you can try upgrading Realm to 10.54.3. Actual testing confirms that the crash does not occur with this version, but functional abnormalities remain.

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

No branches or pull requests

1 participant