Swift app crashes on a device when func configuration is called

After upgrading Realm from 10.28.1 to 10.33.0, my app crashes whenever func configuration<T: BSON>(partitionValue: T) is called.
The error message only says, “RealmSwift/Sync.swift:314: Fatal error: what’s best in this case?”.

What is “this case”??? Does anybody know what is happening?

The strange thing is that it works fine on a simulator. It only crashes on a device.

According to the Atlas log, Authentication → login is OK. But it crashes when I try to get a config for the user.

let configuration = user.configuration(partitionValue: Constants.REALM_PARTITION)

I know that the default clientResetMode is switched from .manual to .recoverUnsyncedChanges in 10.32.0.

I tried to specify manual. But it didn’t help. I get the same fatal error.

let configuration = user.configuration(partitionValue: Constants.REALM_PARTITION, clientResetMode: ClientResetMode.manual())

Can you clarify the question a bit? The code provided doesn’t really tell us about what’s being passed in your functions. For example this could be an issue

let configuration = user.configuration(partitionValue: Constants.REALM_PARTITION)

as we don’t know what Constants.REALM_PARTITION resolves to. Can you provide a bit more code and details?

Also, when you tried .manual did you define a recovery handler?

Are you verifying that user is a valid, authenticated user?

Hi Jay. Thanks for your help.

func openRealm(user: User) throws {
    print("user.id: ", user.id)
    let configuration = user.configuration(partitionValue: Constants.REALM_PARTITION)
    print("configuration: ", configuration)
    realm = try Realm(configuration: configuration)
}

Constants.REALM_PARTITION is a partition value in String. I don’t know if this is helpful. But it is defined as "songbook=default".

No, I didn’t define a recovery handler when I tried .manual.

user is a valid user. I can print it and confirm the user id. user comes from app.login(credentials: Credentials.anonymous), or if let user = app.currentUser.

This is what I get when I print User and Realm.Configuration.

on Device

user.id:  6391d6eb2012602a8e1ae433
RealmSwift/Sync.swift:314: Fatal error: what's best in this case?

on Simulator

user.id:  63912efd8c154e44cbdb3149
configuration:  Realm.Configuration {
	fileURL = file:///Users/kentarookuda/Library/Developer/CoreSimulator/Devices/9B1CDF2B-B213-4D9A-8365-02209D270420/data/Containers/Data/Application/B6B111F0/Documents/mongodb-realm/realm-app-id/63912efd8c154e44cbdb3149/%2522songbook%253Ddefault%2522.realm;
	inMemoryIdentifier = (null);
	encryptionKey = (null);
	readOnly = 0;
	schemaVersion = 0;
	migrationBlock = (null);
	deleteRealmIfMigrationNeeded = 0;
	shouldCompactOnLaunch = (null);
	dynamic = 0;
	customSchema = (null);
}

Here is the stack trace.

Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x37d7c _assertionFailure(_:_:file:line:flags:) + 312
1  RealmSwift                     0x9e724 SyncConfiguration.init(config:) + 314 (Sync.swift:314)
2  RealmSwift                     0x79f04 static Realm.Configuration.fromRLMRealmConfiguration(_:) + 341 (RealmConfiguration.swift:341)
3  RealmSwift                     0x9f8c8 RLMUser.configuration<A>(partitionValue:) + 432 (<compiler-generated>:432)
4  Duet SongBook                  0x4d190 SyncRealmManager.openRealm(user:) + 87 (SyncRealmManager.swift:87)

I rebuilt the app with 10.28.1. And I now get the same fatal error on a device. (It works on a simulator.) So, I guess it has nothing to do with ClientResetMode.

If I reinstall the already published app (that uses 10.28.1), it works perfectly fine on the device.

While upgrading to 10.33.0, I had to change some build settings for the latest XCode. Maybe that messed something up. But in any case, RealmSwift/Sync.swift:314: Fatal error: what's best in this case? is not a very helpful message. It appears that line 314 of Sync.swift is a comment. How can I troubleshoot from here?

Everything works now. It wasn’t the code or realm binary.

I was using Carthage as a dependency manager. During the upgrade process, I did a framework migration. It turned out that the migration was incomplete. The project settings had a link to old frameworks.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.